MD Blog

誰かの何かに役に立てることを書いていきたいです

[iOS] UINavigationControllerからpopされるイベントを検出する

UIViewControllerのプロパティ「isMovingFromParentViewController 」を使う。

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

    // Pop
    if ([self isBeingDismissed] || [self isMovingFromParentViewController]) {

    }
}

UIViewController.hに記述があります。

/*
  These four methods can be used in a view controller's appearance callbacks to determine if it is being
  presented, dismissed, or added or removed as a child view controller. For example, a view controller can
  check if it is disappearing because it was dismissed or popped by asking itself in its viewWillDisappear:
  method by checking the expression ([self isBeingDismissed] || [self isMovingFromParentViewController]).
*/

References

http://stackoverflow.com/questions/10949440/iphone-viewwillappear-only-when-coming-back-from-other-views