2010-08-21 64 views
5

我重写-orientationChanged在我的主视图控制器推ModalViewController一个当设备处于横向模式。当放回肖像模式时,ModalViewController A被解除。但是,在显示ModalViewControllers B,C或D的地方还有其他一些情况(按钮触摸后)。当显示这些设备时,如果设备转为横向并返回,则ModalViewController B C或D将被不正确地解散。如何知道是否显示ModalViewController?

我可以验证-orientationChanged我的主视图控制器,即使当显示ModalViewController正在传递消息。当显示ModalViewController B C或D时,是否有条件可以添加到我的-orientationChanged方法中以绕过该代码?

谢谢!

回答

6

您可以检查是否在您的主视图控制器的modalViewController属性是你的视图控制器之一。

+2

谢谢,这个工作。我使用的条件:if([self.modalViewController isMemberOfClass:[UINavigationController class]])... – ed94133 2010-08-21 23:06:40

1

您可以使用此代码来查找是最后ModalViewController。

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