开发者

UITableView - Color a selectede cell in table (remain colored)

In my app i'm using a UITableViewController ("grouped style") which in one of its section I want the user to be able to see what he had selected by 开发者_JAVA百科making this cell colored and other "uncolored".

Doing it by updating all cells' background color and reloading table data, each time user touches a cell (in didSelectRowAtIndexPath:)

Problem is that there is some processing made in the didSelectRowAtIndexPath: so the color doesn't get changed right a way, rather in a bit delay after touch was made. (I gusse the processing is the resone for the tiny delay)

Is there a better way of doing it?

Any help will be appreciated Liron

P.S. I'm new to all of this...


In order to do this you need to override one of UITableViewCell's methods. You can subclass UITableViewCell and override a method like so:

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {
    [super setHighlighted:highlighted animated:animated];

    // Custom drawing code here
}

This gets fired as soon as a touch is made on a table view cell. If you would like to now have any default coloring on the cell make sure to do the following:

cell.selectionStyle = UITableViewCellSelectionStyleNone;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜