Cell selection style changing on second tap
In my table view I am setting the the selection style inside
- (void)tableView:(UITableView *)iTableView didSelect开发者_开发知识库RowAtIndexPath:(NSIndexPath *)iIndexPath {
MyCell *aCell = (MyCell *)[iTableView cellForRowAtIndexPath:iIndexPath];
aCell.selectionStyle = UITableViewCellSelectionStyleBlue;
Now, the selection style changes on the second tap and not on the first tap. Once a cell is tapped then it works fine if you come back and select it again. What is the reason for this?
I guess the reason for this is that the tableView:didSelectRowAtIndexPath:
method gets called when the cell have already been selected (surprise!). So the default selection style is applied before the method gets called first time, i.e. before you do your aCell.selectionStyle = UITableViewCellSelectionStyleBlue
. When the selection style was changed once, apparently it remains for subsequent calls (taps). To fix this, you have to set the selection style in tableView:cellForRowAtIndexPath:
or tableView:willSelectRowAtIndexPath:
methods, which are called before selecting the cell.
精彩评论