2012-10-16 72 views
12

我已經呼籲第二時間我想上面的代碼之前呈現含有自對象的UIViewController一個UINavigationController用下面的代碼檢查當前視圖控制器

drawController = [[DrawImageViewController alloc] initWithNibName:nil bundle:nil]; 
[drawController setDrawControllerDelegateObject:self]; 
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:drawController]; 
[self presentModalViewController:nav animated:YES]; 
[nav release]; 

但是當知道當前視圖控制器是否出現在屏幕上是drawController。我正在使用以下代碼

if (drawController && [drawController isBeingPresented]) 

但它不適用於我,也適用於iOS 5.0因此我卡在這裏。請幫我知道我應該如何才能知道當前出現在屏幕上的UIViewController是哪個類以及drawContoller是否仍然顯示在屏幕上?對不起,如果有任何錯誤,我會輸入錯誤。任何幫助將不勝感激。

由於內·梅赫達

回答

5

不是最漂亮的代碼,但是這應該工作:

if ([self.presentedViewController isKindOfClass:[UINavigationController class]] && 
    ((UINavigationController *)self.presentedViewController).topViewController == drawController) { 
    … 
21

使用navigationController's visibleViewController propertyisKindOfClass method知道什麼在top

if([self.navigationController.visibleViewController isKindOfClass:[yourcontroller class]]) 
    //exists 
else 
    //not exists 
+1

我得到這個錯誤非常小的,但你必須有[]周圍的自我。 – Lion789

+0

@ Lion789非常感謝你,現在我已編輯:) –

相關問題