Is it possible to determine whether ViewController is presented as Modal?

后端 未结 14 2199
一生所求
一生所求 2020-12-04 07:13

Is it possible to check inside ViewController class that it is presented as modal view controller?

14条回答
  •  余生分开走
    2020-12-04 07:49

    In my project I have a view controller (Detail) that can be presented either modally (when adding a new item) or with push (when editing an existing one) by Master view controller. When user taps [Done] the Detail view controller calls Master view controller's method to notify that it is ready to be closed. Master has to determine how Detail is presented in order to know how to close it. This is how I do this:

    UIViewController *vc = self.navigationController.viewControllers.lastObject;
    if (vc == self) {
        [self dismissViewControllerAnimated:YES completion:NULL];
    } else {
        [self.navigationController popViewControllerAnimated:YES];
    }
    

提交回复
热议问题