如何确定UIViewController是否已被调用为ModalDialog?

Ful*_*ron 6 cocoa-touch modal-dialog uiviewcontroller

在我的应用程序中,我可以在两种模式下调用UIViewControle:Push和ModalDialog.

一旦UIViewController处于活动状态,如何将其称为Push或Modal Dialog,我如何确定?

sud*_*uda 6

您可以modalViewController像这样检查父视图控制器的属性:

if ([self.parentViewController.modalViewController isEqual:self]) {
    NSLog(@"Modal");
} else {
    NSLog(@"Push");
}
Run Code Online (Sandbox Code Playgroud)

只需记住在推送/显示视图后检查它.

  • 这不适用于IOS 5+,因为UIViewController不再响应parentViewController,而是改为呈现ViewController.请参见http://stackoverflow.com/questions/2798653/iphone-is-is-possible-to-determine-wheteher-viewcontroller-is-presented-as-moda (7认同)

sas*_*ash 5

这对我有用:

   if(self.presentingViewController){
        //modal view controller 

    }else{


    }
Run Code Online (Sandbox Code Playgroud)