? ? 當同一個視圖控制器,在同一個時間,只能present一個另外的視圖控制器,如果當前的VC已經present了,再次present一個VC時,就會提示失敗;如果想繼續present,就必須將原來present的控制器dismiss。
? 控制器的兩個可能很多人都沒注意的兩個屬性presentedViewController和presentingViewController;他們分別是被present的控制器和正在presenting的控制器。比如說, 控制器A和B,[A presentViewController B animated:YES completion:nil]; 那么A相對于B就是presentingViewController,B相對于A是presentedViewController,即
? ? ? ? ? ? ? ? B.presentingViewController = A;
? ? ? ? ? ? ? ? ?A.presentedViewController = B;
if(self.presentingViewController.presentingViewController) {
? ? ? ? ? ? ? ? ?self.presentingViewController.view.alpha=0;?
?[self.presentingViewController.presentingViewController dismissViewControllerAnimated:YES completion:nil];
}else{
? ? ? ? ?[self ?dismissViewControllerAnimated:YES completion:nil];
}
可以作為退出當前控制器,
比如說,現在有個C界面,C界面被顯示出來,可能有兩種情況,一是modal出來的,另外一種是push出來的,這時候就可以通過當前界面對象的presentingViewController屬性來判斷到底屬于哪種情況,如果是nil,表示是UINavigationController對象push過來的,如果不是則是modal過來的。