7

I have 2 View Controllers with Navigation Controller. When I Use [self.navigationController popViewControllerAnimated:YES]; in the second one - the first one opens but the methods in viewDidLoad don't called. What are the methods called in the first one controller in this situation?

ShurupuS
  • 2,923
  • 2
  • 24
  • 44
  • The view is already loaded, they don't unload until they get popped off. Don't use ARC if you're new, just my recommendation. – Stephen J Jul 13 '13 at 00:53
  • See Also: http://stackoverflow.com/questions/1557290/how-to-trap-the-back-button-event – Senseful Jan 31 '14 at 19:45

2 Answers2

26

The navigation controller sends viewWillAppear: to a view controller before putting its view on the screen, and viewDidAppear: after.

Inside viewWillAppear: and viewDidAppear:, the view controller can check self.isMovingToParentViewController. If isMovingToParentViewController is YES, the view controller is being added to the navigation controller in the first place (presumably because it's the navigation controller's root view controller, or because it is being pushed). If isMovingToParentViewController is NO, the view controller is already in the navigation controller's stack, and another view controller is being popped to reveal it.

Read “Handling View-Related Notifications” in the UIViewController class reference.

rob mayoff
  • 375,296
  • 67
  • 796
  • 848
1

In that case viewWillAppear method will be called.

-(void)viewWillAppear:(BOOL)animated
{

}
Dilip Manek
  • 9,095
  • 5
  • 44
  • 56