开发者

Flash background color of a UITableViewCell on reload

I have a UITableView in my app. Selecting a cell f开发者_JAVA技巧rom 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?


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


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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜