views:

721

answers:

3

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
I prefer calling the `deselectRowAtIndexPath` in my viewDidAppear, if select the row brings up a new view.
notnoop
IIRC, that's where UITableViewController calls it.
Daniel Tull
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
@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
@4thSpace how are you calling deselect now?
paulthenerd
I'm not calling deselect and not sure what I did to cause it to get stuck.
4thSpace
@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
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
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