如何判断是否存在模态UIViewController?

ohh*_*hho 15 iphone uiviewcontroller

有没有办法告诉是否有一个模态UIViewController已经提出,比如说,在调用之前dismissModalViewControllerAnimated

Swi*_*ect 18

iOS 9,8,7,6和5

这个问题的答案太多了,没有一个涵盖所有案例.此外,尽管您在文档中找到了什么,但现在已弃用的有两种替代方法modalViewController:

  1. 如果你需要知道是不是莫代尔:

    BOOL modal = nil != [self presentingViewController];

  2. 如果你需要知道你是否模态覆盖:

    BOOL hiddenByModal = nil != [self presentedViewController];


Pra*_*n S 9

iOS6 + - 使用presentsViewController: 因为iOS 6,presentedViewController应该使用modalViewController已被弃用的

使用该属性:

不推荐使用 - modalViewController: 活动模态视图的控制器 - 即临时显示在接收器管理的视图顶部的视图.(只读)

@property(nonatomic, readonly) UIViewController *modalViewController
Run Code Online (Sandbox Code Playgroud)

  • 在iOS6中弃用,使用presentViewController (9认同)