1

I have a cell with a few lines of text which changes colour when selected/highlighted. The problem is that as the new viewController is being pushed, the deselection animation occurs which is visually distracting as the text suddenly reverts to the unselected state. I have moved the deselectRowAtIndexPath statement after the line where the new view controller is pushed, but this has no effect.

How can I prevent the user seeing the cell deselection (without implementing a timer)? Any help would be appreciated please.

RunLoop
  • 20,288
  • 21
  • 96
  • 151

2 Answers2

9

If you're using a UITableViewController, you won't need to call deselectRowAtIndexPath:. This will be done for you automatically when your table view becomes visible again.

If you're not using a UITableViewController because you have a more complicated interface, you would need to call deselectRowAtIndexPath: manually from the viewWillAppear:animated: method.

Alex
  • 26,829
  • 3
  • 55
  • 74
  • That's interesting, didn't know that bit of trivia. – wkw Dec 10 '09 at 17:46
  • I am using a tableViewController, but the row is not automatically deselected when the pushed vc is popped – RunLoop Dec 10 '09 at 17:58
  • You subclassed UITableViewController? If so, are you calling `[super viewWillAppear]`? If you read the Overview section for UITAbleViewController, I see it does discuss the various behaviors the UITAbleViewController base class provides. – wkw Dec 10 '09 at 21:09
7

I think the general paradigm used with table views and pushing new VCs is that you deselect the table row in your viewWillAppear:animated method. Then as the VC is popped, they see which row had been used to navigate to that VC.

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

    [self.myTableView deselectRowAtIndexPath:[myTableView indexPathForSelectedRow] animated:YES];

}

so remove deselectRow from your didSelectRowAtIndexPath method.

wkw
  • 3,865
  • 3
  • 25
  • 24
  • Thanks, that makes sense. However, my viewWillAppear method is not firing? – RunLoop Dec 10 '09 at 17:55
  • 1
    Update: viewWillAppear is not firing as I am using a navigation controller, so I have implemented - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated – RunLoop Dec 10 '09 at 18:07