What would cause a tableview cell to remain highlighted after being touched? I click the cell and can see it stays highlighted as a detail view is pushed. Once the detail view is popped, the cell is still highlighted.
+5
A:
In your didSelectRowAtIndexPath you need to call deselectRowAtIndexPath to deselect the cell.
So whatever else you are doing in didSelectRowAtIndexPath you just have it call deselectRowAtIndexPath as well.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Do some stuff when the row is selected
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
paulthenerd
2009-12-03 15:43:00
I prefer calling the `deselectRowAtIndexPath` in my viewDidAppear, if select the row brings up a new view.
notnoop
2009-12-03 15:59:40
IIRC, that's where UITableViewController calls it.
Daniel Tull
2009-12-03 17:48:42
Actually that is not the right place to call it, really... try using an Apple app with tables (Contacts is a good one) and you'll see after you push out to a new screen, on return the cell is still highlighted briefly before being deselected. In theory I think you do not have to do any extra work to have it deselect right away on its own, so code in viewDidAppear should not be needed...
Kendall Helmstetter Gelner
2009-12-03 20:40:27
@Kendall: Yes - that is exactly what I want, which seems it should be the default behavior. However, mine stays selected upon return. Do you have any ideas?
4thSpace
2009-12-03 22:31:23
@4thSpace how are you calling deselect now?
paulthenerd
2009-12-03 23:13:21
I'm not calling deselect and not sure what I did to cause it to get stuck.
4thSpace
2009-12-04 05:50:25
@Kendall, @4thSpace: Maybe my last comment was confusing as to who I was referring to, apologies for that.UITableViewController calls the `-deselectRowAtIndexPath:animated:` method on its tableView property from `-viewDidAppear`.However, if you have a table view in a UIViewController subclass, you should call `-deselectRowAtIndexPath:animated:` from `-viewDidAppear` yourself. :)
Daniel Tull
2009-12-04 12:19:40
A:
Did you subclass -(void)viewWillAppear:(BOOL)animated
? The selected UITableViewCell won't deselect when you don't call [super viewWillAppear:animated];
in your custom method.
HansPinckaers
2010-01-08 13:41:07
A:
HansPinckaers, thanks so much. This is what happened to me. I actually changed my method from viewDidAppear to viewWillAppear but had forgotten to change the [super viewDidAppear] to [super viewWillAppear].
Luke
2010-09-09 01:46:53