Determining Why a View’s Appearance Changed
Occasionally, it can be useful to know why a view is appearing or disappearing. For example, you might want to know whether a view appeared because it was just added to a container or whether it appeared because some other content that obscured it was removed. This particular example often appears when using navigation controllers; your content controller’s view may appear because the view controller was just pushed onto the navigation stack or it might appear because controllers previously above it were popped from the stack.
The UIViewController class provides methods your view controller can call to determine why the appearance change occurred. Table 5-1 describes the methods and their usage. These methods can be called from inside your implementation of the viewWillAppear:, viewDidAppear:, viewWillDisappear: and viewDidDisappear: methods.
Table 5-1 Methods to call to determine why a view’s appearance changed
isMovingFromParentViewController
You call this method inside your viewWillDisappear: and viewDidDisappear: methods to determine if the view controller’s view is being hidden because the view controller was removed from its container view controller.
isMovingToParentViewController
You call this method inside your viewWillAppear: and viewDidAppear: methods to determine if the view controller’s view is being shown because the view controller was just added to a container view controller.
isBeingPresented
You call this method inside your viewWillAppear: and viewDidAppear: methods to determine if the view controller’s view is being shown because the view controller was just presented by another view controller.
isBeingDismissed
You call this method inside your viewWillDisappear: and viewDidDisappear: methods to determine if the view controller’s view is being hidden because the view controller was just dismissed.