Checking if a UIViewController is about to get Popped from a navigation stack?

后端 未结 15 980
说谎
说谎 2020-12-04 19:17

I need to know when my view controller is about to get popped from a nav stack so I can perform an action.

I can\'t use -viewWillDisappear, because that gets called

15条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-04 19:27

    You can catch it here.

    - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    
        if (viewController == YourAboutToAppearController) {
                // do something
        }
    }
    

    This will fire just before the display of the new View. Nobody's moved yet. I use all the time to do magic in front of the asinine NavigationController. You can set titles and button titles and do whatever there.

提交回复
热议问题