开发者

UITableView Cell background color fade away

How can I give a tableView cell background color the fade effect as soon as it appears. I know how to get a cell selected when the table view appears but the color persists for ev开发者_StackOverflower. I would like it to stay there for a while (2 seconds or whatever) and then fade away. Can anyone help me with this?

Off the top of my head, I am thinking NSTimer could be called into use here. What do the experts have to say?


Forget about timers, they are just too much work in this case. Just make a deselectSelectedCell method and call it using an asynchronous call:

    [tableView performSelector:@selector(deselectSelectedCell) withObject:nil afterDelay:2.0];

and the method:

- (void)deselectSelectedCell{
[tableView deselectRowAtIndexPath:[tableView indexPathForSelectedRow] animated:YES]
}

This will deselect the cell, off course. If you want you cell to remain selected, probably you should change the color of the contentView .


Make sure that you are performing deselectSelectedCell on the object where it is defined, or you will get the "unrecognized selector" error. In the example, tableView and self are the same thing. If your tableview is not the same as self, then you need to call performSelector on self instead of on tableView.

[self performSelector:@selector(deselectSelectedCell) withObject:nil afterDelay:2.0];

and the method

- (void)deselectSelectedCell {
    [someCustomTableView deselectRowAtIndexPath:[someCustomTableView indexPathForSelectedRow] animated:YES];
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜