The -viewWillApear method is reasonable, but it is called when the view should be inserted into the view hierarchy, which may or may not be what you want.
If you want more control over push / pull progress, you can override
- (void)willMoveToParentViewController:(UIViewController *)parent { if (nil == parent) { // Moving to nil parent means being removed from parent } else { // Will be inserted as a child view controller of <parent> } } - (void)didMoveToParentViewController:(UIViewController *)parent { if (nil == parent) { // Moving to nil parent means was just removed from parent } else { // Was just inserted as a child view controller of <parent> } }
They will be called immediately before and after the navigation controller pushes / pushes the child view controller.
From the documents ...
didMoveToParentViewController:
Called after the view controller is added or removed from the container view controller.
- (void)didMoveToParentViewController:(UIViewController *)parent
Options
the parent
The parent view controller, or nil if there is no parent.
Discussion
The controller of your view can override this method when it wants to respond to being added to the container.
and...
willMoveToParentViewController:
Called immediately before adding or removing a view controller from the container controller.
- (void)willMoveToParentViewController:(UIViewController *)parent
Options
the parent
The parent view controller, or nil if there is no parent.
Discussion
The controller of your view can override this method when it needs to know that it is added to the container.
source share