Darren
Darren

Reputation: 10129

Flash background color of a UITableViewCell on reload

I have a UITableView in my app. Selecting a cell from the table view adds a subview over top where the user can edit the contents of the table view cell. After the user dismisses the subview, the edited cell is reloaded using the UITableView instance method reloadRowsAtIndexPaths:withRowAnimation:

I want the edited cell to flash it's contentView.background color as an indicator of which cell has just been updated. I know about UITableViewRowAnimation, but it doesn't give me the effect that I want.

Any suggestions on the best way to accomplish this?

Upvotes: 0

Views: 3747

Answers (2)

steve
steve

Reputation: 825

A little late, but I think I found a good way to do this (just grabbing the first cell as an example):

NSArray* cells = [self.tableView visibleCells];
UITableViewCell* cell = [cells objectAtIndex:0];
NSIndexPath* path = [self.tableView indexPathForCell:cell];
for (int i = 0; i <= 20; i++)
{
    UIColor* color = nil;
    if (i % 2 == 0) 
    {
        color = [UIColor whiteColor];
    }
    else 
    {
        color = [UIColor grayColor];
    }
    NSMutableArray* stuff = [[NSMutableArray alloc] initWithCapacity:2];
    NSArray* rowsToReload = [NSArray arrayWithObjects:path, nil];
    [stuff addObject:rowsToReload];
    [stuff addObject:color];
    [self performSelector:@selector(flash:) withObject:stuff afterDelay:i * .2];
}

And have this method:

-(void)flash:(NSMutableArray*)stuff
{
    NSArray* rowsToReload = [stuff objectAtIndex:0];
    self.flashColor = [stuff objectAtIndex:1];
    [self.tableView reloadRowsAtIndexPaths:rowsToReload withRowAnimation:UITableViewRowAnimationNone];
}

Then, in your cellForRowAtIndexPath (you probably want something after this method which sets the flashColor back to nil):

if (self.flashColor != nil) cell.backgroundColor = self.flashColor;

Upvotes: 1

Evan Cordell
Evan Cordell

Reputation: 4118

Is [tableview reloadRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationFade] unacceptable?

Upvotes: 2

Related Questions