如何知道是否显示ModalViewController?

时间:2010-08-21 22:23:23

标签: iphone uiviewcontroller modalviewcontroller

我在主ViewController中覆盖-orientationChanged,以便在设备处于横向模式时推送ModalViewController A.当以纵向模式放回时,ModalViewController A被解除。但是,还有其他情况(按钮触摸后),其中显示了ModalViewControllers B,C或D.当这些设备显示时,如果设备转向横向并向后转,则ModalViewController B C或D将被不适当地解除。

即使显示了ModalViewController,我也可以验证我的主ViewController上的-orientationChanged是否正在发送消息。有没有条件我可以添加到我的-orientationChanged方法,以便在显示ModalViewController B C或D时绕过该代码?

谢谢!

2 个答案:

答案 0 :(得分:6)

您可以检查主viewcontroller中的modalViewController属性是否是您的一个视图控制器。

答案 1 :(得分:1)

您可以使用此代码查找最后一个ModalViewController。

UIViewController *leafController = self;
while(true) {
    if (leafController.modalViewController) {
        leafController = leafController.modalViewController;
        continue;
    }
    break;
}
[leafController presentModalViewController:showController animated:YES];