Reputation: 2473
In an other question it was told to reload only the needed UITableViewCells instead of the whole table.
How can this be done. I must say, currently I'm a bit clueless, cause my custom cells are not "directly" bound to a tableView. I instantiate them in the cellForRowAtIndexPath method.
//default
static NSString *CellIdentifier = @"Cell";
TwoRowCell *cell = (TwoRowCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"TwoRowCell" owner:self options:nil];
cell = (TwoRowCell *)[nib objectAtIndex:0];
}
// Configure the cell...
cell.title.text = [dict objectAtIndex:indexPath.row];
cell.value.text = @"";
return cell;
how can I get access to the cells and reload only the cell. Idea: having some delegate-methods and there when updating a cell reload the cell. Currently I reload the whole table.
BR, mybecks
Upvotes: 0
Views: 285
Reputation: 9320
Just call reloadData on your table - that does not reloads the whole table, it only reloads the cells that are (or more precisely should become) visible.
Your cells are directly related to the table, and cellForRowAtIndexPath is the bridge - that is what the system calls to determine how to show a cell. For example, this method is called many times when you scroll.
In one situation in the past, I called reloadRowsAtIndexPaths to only reload one (or more) particular cell(s). In that case I had a button on the cell, and I wanted to disable the button after it was clicked once.
Upvotes: 2
Reputation: 4879
If some of your data changed, you can call - (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation
on your UITableView
to reload only this UITableViewcell
. It will call cellForRowAtIndexPath again.
Upvotes: 2