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

后端 未结 14 2188
一生所求
一生所求 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:45

    A hack like this might work.

    UIViewController* child = self;
    UIViewController* parent = child.parentViewController;
    while (parent && parent.modalViewController != child) {
        child = parent;
        parent = child.parentViewController;
    }
    if (parent) {
        // A view controller in the hierarchy was presented as a modal view controller
    }
    

    However, I think my previous answer is a cleaner solution.

提交回复
热议问题