Search code examples
iosuitableviewuser-interfaceuiviewcontrollerviewwillappear

Appropriate place to deselect a row


I have been experimenting a little with using UITableView's deselectRowAtIndexPath: to help the user know which row was being viewed when returning to the tableview.

I've noticed that I can place this in viewWillAppear and viewDidAppear with slightly different results. The first begins the animation as the popped view slides out, while the latter only begins the animation once the popped view is completely gone. As a result, the latter feels more 'pronounced', I guess (more of the animation occurs with the row fully on screen - in fact all of it).

Aesthetically, this is a useful distinction, since I get more control over the user experience. However, some questions:

  • Is there any technical reason I should use one over the other?
  • Looking carefully at some of Apples applications I think they are animating in viewWillAppear. Can anyone confirm?
  • Is there a risk using viewWillAppear that the animation will complete offscreen (maybe due to some laggy processing etc in the popped view controller)? Or does it only fire at the beginning of the transition from the popped view?

Solution

  • 1) If your code is dependent on the view being fully loaded, viewDidAppear is better, but in this case I don't think it makes a technical difference.

    2) I don't think any of us work at Apple...

    3) viewWillAppear by definition is called just before the view begins to show itself. If your animation takes longer than the view takes to appear then yes, it will be offscreen. Otherwise it will be (Animation length - (minus) Time for view to appear)