I am using table view in my app, the task is multiple deletion of cells like iPhone message application. My problem is when select the cells check box and scroll the table then selected cells check marks are deselect. What is the problem?
When you scroll the table then its reload function automatically called. Thats why your selection have cleared. do one thing when you checked your check boxes then stores that values in an array after that call an custom reload function and in that reload your all values in your table...
You need to Manage an array which contain the indexes of the rows for which you select a checkbox.
in cellForRowAtIndexPath: delegate method check whether the row index is in your index array show the checked image otherwise show unchecked image.
UITableView will reuse your tableviewcell, that means it will never keep many cell object, just 5~6 cell maybe. It will save a lot of memory, but it may not keep the state you have set. So you must keep the data by yourself and assign to the cell in
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
Related
I have a UITableView to display a list of data.
The list will contain images, so I am loading images with lazy loading. Now I don't want to load the whole list at a time.
The loading should be like, first it should load some 10 records and when we scrolling down to the tableview, it should automatically load next 10 records as on.
For this I need to add rows when I am scrolling to bottom. The tableview may contain different sections.
So how can I add new rows and new sections at the end of the tableview while scrolling down?
Look at the Apple documentation about UITableView.
You can use the following method to add a row :
- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;
Firstly, the thing you want to do is known as Lazy Loading.
Means your table view will load images or show data in the cells which are currently visible to user. So have a look at this link. It provides sample code that might help you.
And to insert row, you can use
(void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;
At
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == [yourArray count]-1)
{
//start fetching the next set of data in background asynchronously and when fetching is complete use delegate methods to reload or append your current UITableView , meanwhile start a activity indicator as footer to show loading
}
}
this is the effective method, if you try to implement synchronously when scrolling reaches bottom, it will make your device stuck
I created a custom cell for my table view and for the most part everything seems to be working fine, but when I select one of the rows (which takes me to another UIView), then come back from the subsequent view via the nav controller, the selected cell is not in highlighted state. How to display the selected cell in highlighted state when i come back?
any help is appreciated in advance, thanks.
when you are coming back from anotherview make sure that save the selectedCell and then in viewwillappear method reloaddata.in cellforindexpath write the code of selection style uitableviewcellselectionstyleblue
As #sachin said, you should save selected index path
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
self.selectedIndexPath = indexPath;
}
and in
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
You should check if indexPath is equal to selectedIndexPath,
but you should be aware that Apple discoureges that kind of behavior in HIG: http://developer.apple.com/library/ios/#DOCUMENTATION/UserExperience/Conceptual/MobileHIG/UIElementGuidelines/UIElementGuidelines.html
In rare cases, a row might remain highlighted when secondary details
or controls related to the row item are displayed in the same screen.
However, this is not encouraged because it is difficult to display
simultaneously a list of choices, a selected item, and related details
or controls without creating an uncomfortably crowded layout.
In my application, I am using tableview with some rows. In each row I am displaying some part
of text.In that row below text there is a Expandbtn. If we click that we will display the whole
text.
For that I want to use reloadRowsAtIndexPaths: WithAnimation: method . I want to apply this
method when I click Expandbtn in each cell.
I am using that above method for expanding text in cell. My Problem If I expand text in first
and go to 2nd cell it appears to be expanding and it is overlaping with first cell.
If I scroll the table to the top, then first cell appears to be NOT Expanding.
Can Anyone Help me in this.
Thanks in Advance.
Relating to "If I scroll the table to the top, then first cell appears to be NOT Expanding." It sounds like you are not dynamically determining the height of the rows.
Are you implementing the delegate method - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath in your NSTableViewController? If so, make sure you are returning a different value before and after you expand the row.
In my application there is a table view.What I want to do is when I scrolls the table view and when it come to its end row I want to perform some action.
Please tell me which approach should I use to do this.
Thanks in advance!!
I think you should make a check in
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)
when it loads the last row then call that method.
I think this will work. because table does not load all data at once but i loads data when user scroll
I think (don't the docs up here) but there is no method within the UIScrollViewDelegate that handles the scrolling to the bottom. There is when scrolling to top, but can't remember if there is scrolling to bottom. Check it please.
If not, the easy way is just to check the indexpath.row at cellForRow. If it is your last row, call whatever action you want.
I have a Table View Controller with cells. I want to update the text that is displayed on the visible UITableViewCells. Is there a way to get a reference to the cells that are currently on the screen?
You can query the visible cells;
[myTableOutlet visibleCells];
Where myTableOutlet refers to your UITableView, and visibleCells returns an array of table cells. You could also use indexPathsForVisibleRows, which will return an array of index paths for the rows that are currently visible.
If you put the code in a ,notification triggered, function, you could update only the currently visible cells.
What you can do is go and ask for the cells at index paths using - (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath, if they are not nil, you know they are on the screen and you can do what you wish with them. Also if you know the visible rectangle on the screen (which shouldnt be hard to get) you can use tableViews - (NSArray *)indexPathsForRowsInRect:(CGRect)rect and you can get all your visible index paths and use cellForRow in order to get the cells back.
As long as this is marked as answer, I stand corrected, like others said you can do [tableView visibleCells]
Call the reloadData method of the UITableView. It will force the table view to update all the visible cells information (check the documentation for more information).