2010-08-21 66 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];