In my iPhone app I have a table view where I add a tick image to a cell if that objects ‘isConfirmed’ value is true. When entering the detailed view I can edit the confirmed value, and upon popping back to the main table view I need to see the update and not only when I view the main table from a fresh.
So I am using this code in my tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath method`:
UIImageView *tickImg = nil;
//If confirmed add tick to visually display this to the user
if ([foodInfo.isConfirmed boolValue])
{
tickImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ConfirmedTick.png"]];
[tickImg setFrame:CGRectMake(0, 0, 32, 44)];
[cell addSubview:tickImg];
}
else
{
[tickImg removeFromSuperview];
}
What this does it successfully add the tick image to my cells which have a true value for isConfirmed and when going into the detail view of an object and setting it to TRUE and retuning, the tick appears, however I can’t get it to work the other, so if the tick is there and I go into the detail view to unconfirmed it, the tick doesn’t disappear.
Are you calling [self.tableView reloadData]; on the VC’s viewWillAppear:?
Also, the approach you’re using to configure the cell is error-prone. Since the tableView is reusing the cells, you can’t be sure what state a cell is in when you dequeue it.
A better approach would be to build the cells consistently: