Reputation: 317
I have a UITableView and have it so when you press the first cell, it takes you to a new view (new xib). When you press the second cell, you go to another view and so on. When you go to any of those new views, and come back to the tableview view, the cell you just pressed is still selected (its highlighted blue). What is the code to fix this?
Upvotes: 1
Views: 1129
Reputation: 10312
Inside viewWillAppear of your tableView whose cell you wish to remove selection from:
UITableViewCell *cell = (UITableViewCell *)[myTableView cellForRowAtIndexPath:lastSelected];
[cell setSelected:NO];
Where lastSelected can be a global var of type NSIndexPath storing indexPath from the didSelectRowAtIndexPath of the above UITableView
Upvotes: 1
Reputation: 3152
It's quite easy..
In the same method that you push the new view you should add the line:
[tableView deselectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated];
Upvotes: 0
Reputation: 1804
In your tableView datasource delegate method:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
Upvotes: 4