When the users taps on a cell, I want to update my UITableView
; including the contents of this tapped cell. Easiest way is to update internal parameters and then invoke [self.tableView reloadData];
.
However, reloadData
immediately stops the nice blue->none selection animation of my tapped cell.
Is there a (standard) way to update my table cells without stopping the tapped cell's animation?
Note in this case I don't add or delete cells; I just want to contents to change (e.g. start an activity indicator, or change the color of labels.)
In your case you can just get pointers to all visible cells and update them. Something like this:
- (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath { NSArray* visibleCells = [tableView indexPathsForVisibleRows]; for (NSIndexPath* indexPath in visibleCells) { UITableViewCell* cell = [self.tableView cellForRowAtIndexPath:indexPath]; [self updateCell:cell atIndexPath:indexPath]; // Your method, which updates content... } }
And if you want to update other cells content you can use something like this:
- (void)tableView:(UITableView*)tableView willDisplayCell:(UITableViewCell*)cell forRowAtIndexPath:(NSIndexPath*)indexPath { [self updateCell:cell atIndexPath:indexPath]; // Your method, which updates content... }
So your cells will always display correct content.
About creating content:
- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString* CellIdentifier = @"Cell"; UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; [self createContentForCell:cell atIndexPath:indexPath]; // so here to create content or customize cell } return cell; }
Or maybe you could simply delay the reload of your table data as described for example here: Delay reloadData on UITableView