I need to set different styles for cells that I have inserted compared to reloaded ones.
I am inserting my cells like the following:
[tempArray addObject:[NSIndexPath indexPathForRow:0 inSection:0]];
[[self tableView] beginUpdates];
[[self tableView] insertSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationTop];
[[self tableView] insertRowsAtIndexPaths:(NSArray *)tempArray withRowAnimation:UITableViewRowAnimationNone];
[[self tableView] endUpdates];
Is there a way for me to do the following:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (cell was inserted) {
cell.mylabel.textColor = [UIColor redColor];
} else {
cell.mylabel.textColor = [UIColor blackColor];
}
}
As is often the case for maintaining the state of a table view cell, the right answer is to keep the state in your model. In other words, if tempArray is your model containing a collection of objects that describe the table’s contents, add a BOOL attribute to those objects meaning something like
userAdded.Then your “cell was inserted” pseudo-code can become: