UINavigationViewControllerで、戻るボタンを押したときに処理を実行


stackoverflow:Find out if user pressed the back button in uinavigationcontroller?

iOS 5.0より前のバージョンではnavigationControllerが現在のコントローラを持っているかチェックする。(willDisappearだけど、既にコントローラは除去されているようです)
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];

    if (![[self.navigationController viewControllers] containsObject:self]) {
        // We were removed from the navigation controller's view controller stack
        // thus, we can infer that the back button was pressed
    }
}
iOS5.0以降なら、-didMoveToParentViewController を使う。

- (void)didMoveToParentViewController:(UIViewController *)parent
{
    // parent is nil if this view controller was removed
}

Comments

comments

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です