
? ? 當(dāng)同一個(gè)視圖控制器,在同一個(gè)時(shí)間,只能present一個(gè)另外的視圖控制器,如果當(dāng)前的VC已經(jīng)present了,再次present一個(gè)VC時(shí),就會(huì)提示失?。蝗绻肜^續(xù)present,就必須將原來(lái)present的控制器dismiss。
? 控制器的兩個(gè)可能很多人都沒(méi)注意的兩個(gè)屬性presentedViewController和presentingViewController;他們分別是被present的控制器和正在presenting的控制器。比如說(shuō), 控制器A和B,[A presentViewController B animated:YES completion:nil]; 那么A相對(duì)于B就是presentingViewController,B相對(duì)于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];
}
可以作為退出當(dāng)前控制器,
比如說(shuō),現(xiàn)在有個(gè)C界面,C界面被顯示出來(lái),可能有兩種情況,一是modal出來(lái)的,另外一種是push出來(lái)的,這時(shí)候就可以通過(guò)當(dāng)前界面對(duì)象的presentingViewController屬性來(lái)判斷到底屬于哪種情況,如果是nil,表示是UINavigationController對(duì)象push過(guò)來(lái)的,如果不是則是modal過(guò)來(lái)的。