判斷ViewController push、pop操作

weixin_33895657發表於2018-03-22

在viewWillDisappear中判斷當前控制器是push操作還是pop操作:

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

    NSArray *viewControllers = self.navigationController.viewControllers;
    if (viewControllers.count > 1 && [viewControllers objectAtIndex:viewControllers.count-2] == self) {
        //為push操作
        
    } else if ([viewControllers indexOfObject:self] == viewControllers.count-1) {
        //為pop操作
    }
}

相關文章