views:

42

answers:

1

I have a UITableView where I have the backgroud color set via

UIView *myView = [[UIView alloc] init];
if ((indexPath.row % 2) == 0)
    myView.backgroundColor = [UIColor greenColor];
else
    myView.backgroundColor = [UIColor whiteColor];

cell.backgroundView = myView;
[myView release];

The problem I find is that when I edit a table (via setEditing:YES...) some cells of the same color invariable are next to each other. How do I force UITableView to fully redraw. reloadData is not doing a great job.

Is there are deep-cleaning redraw?

+1  A: 

I had this issue before so I'll share with you how I solved it:

You can use a boolean flag (say it's called needsRefresh) to control the behavior of cell creation in -cellForRowAtIndexPath:

An example:

- (UITableViewCell*) tableView:(UITableView *) tableView cellForRowAtIndexPath:(NSIndexPath*) indexPath {
    UITableViewCell *cell = [tableView dequeueResuableCellWithIdentifier:SOME_ID];
    if(!cell || needsRefresh) {
       cell = [[UITableViewCell alloc] init....];
    }
    //.....
    return cell;
}

So, when you need a hard reload, set the needsRefresh flag to YES. Simple as a pimple.

Jacob Relkin
It works. My program has a very complicated cell structure, so I had missed the right spot to apply your suggestion. Sorry for the inconvenience.
John Smith