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

后端 未结 15 966
说谎
说谎 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:38

    Try overriding willMoveToParentViewController: (instead of viewWillDisappear:) in your custom subclass of UIViewController.

    Called just before the view controller is added or removed from a container view controller.

    - (void)willMoveToParentViewController:(UIViewController *)parent
    {
        [super willMoveToParentViewController:parent];
        if (!parent) {
            // `self` is about to get popped.
        }
    }
    

提交回复
热议问题