1

我在這裏得到了一個非常有趣的問題。我的iPhone應用程序在AppDelegate中有一個UITabbarController作爲rootViewController。UITabbarController關閉模式UINavigationController

如果應用程序第一次打開,它必須基本配置。爲了這個目的,我創建的UINavigationController,並告訴tabbarController到模態呈現它:

firstRun = [[firstRunViewController alloc] init]; 
navCtrl = [[UINavigationController alloc] initWithRootViewController:firstRun]; 
[[self tabBarController] presentModalViewController:navCtrl animated:NO]; 

當配置完成後,我想擺脫firstRunViewController的。我經常使用這種技術,使用-dismissModalViewControllerAnimated:

但在這個星座這不起作用。從我稱之爲解僱的控制者來看,這並不重要。 我試圖通過tabbarController,rootViewController,當前活動viewController,導致self和其他幾個控制器。

我每次打電話-dismissModalViewControllerAnimated:我得到這個異常:

'UIViewControllerHierarchyInconsistency', reason: 'presentedViewController for controller is itself on dismiss for: <UINavigationController:… 

有人能幫忙嗎?由於提前,以親切的問候,朱利安

編輯 在我的AppDelegate我使用的UITabBarController作爲RootViewController的主窗口:

self.window.rootViewController = self.tabBarController; 
[self.window makeKeyAndVisible]; 

然後我創建的UINavigationController,告訴的UITabBarController呈現modalViewController:

UINavigationController *navCtrl = [[UINavigationController alloc] initWithRootViewController:firstRun]; 
[[self tabBarController] presentModalViewController:navCtrl animated:NO]; 

當我現在請-dismissModalViewControllerAnimated:在firstViewController我得到錯誤FR om以上。

回答

1

我終於自己找到了答案! 我只是看不到樹木!我現在很開心! :)

我做了真正愚蠢的事情:在設置viewControllers的最後一個viewController我不得不改變tabars viewControllers對應於用戶是否是管理員。所以我做了:

appDelegate.tabBarController.viewControllers = [NSArray arrayWithObjects:appDelegate.readState, 
               appDelegate.navCtrl, 
               appDelegate.settings, nil]; 

你可以看到我正在將AppDelegate的「navCtrl」添加到tabbar的viewControllers。所以我試圖解僱我剛添加到parentViewControllers(UITabbarController)子控制器的viewController。

解僱我想在同一時間呈現的東西是不可取的! :))

1

在我看來,你濫用UITabbarController。即使UIViewController的子類,這個類也沒有真正使用UIViewController的大部分基礎結構。

你想要什麼是你現在擁有的東西的略微延伸。在appDelegate中創建一個新的UIViewController子類,並將其作爲單個對象添加到數組中,並將tabBar的viewControllers設置爲該數組。設置你的子類的hidesBottomBarWhenPressed爲YES,這樣它就隱藏了標籤欄,當它變得可見時。

現在您的應用程序將啓動,您的UIViewController子類將成爲最前面的視圖。您可以使這個視圖成爲您想要以模態方式呈現的視圖,或者您可以使用某種動畫從您的子類中呈現該視圖。哦,如果你使用啓動視圖作爲你的子類的背景圖像,你可以真正實現這個平滑過渡 - 我現在就這樣做。

當你的模式的看法做了,那麼你可以實例要然後顯示任何意見,並設置的UITabBarController使用具有tabBarController.viewControllers(或動畫版)的意見。噗,你的UIViewController將會被替換(並且在ARC下消失)。

+0

這類作品...但我不能應用動畫。我試圖在最後一個模式viewController上添加[UIView animateWithDuratio:]。但動畫只是不顯示。 –

+0

我真的很想了解問題所在。因爲我提出了一個modalViewController(日常業務),就像我一樣,當我提出我的login-viewController時。我認爲問題是更多的一個實例,導航控制器... –

1

我沒有機會測試我的假設,但我懷疑這個問題可能取決於您提出模態視圖太早的事實,即太早意味着在主窗口有機會之前設置標籤欄控制器。所以,我建議這個變化:異步

- (void)initializeAndPresentNavigationController { 
    UINavigationController *navCtrl = [[UINavigationController alloc] initWithRootViewController:firstRun]; 
    [[self tabBarController] presentModalViewController:navCtrl animated:NO]; 
} 
  • ,而不是直接從appDidFinishLaunching呈現導航控制器,調用上述方法:

    1. 創建方法實例導航控制器

      [self performSelector:@selector(initializeAndPresentNavigationController) withObject:nil afterDelay:0.0]; 
      

    這裏調用方法的技巧我在2中做的是,initializeAndPresentNavigationController的調用將被簡單地推到主循環上,並在應用程序有可能構建其初始UI之後執行。

    希望它適合你。

  • +0

    嘿塞爾吉奧!謝謝你的幫助。但是這個解決方案不起作用。它導致相同的錯誤**呈現控制器的ViewViewController本身就是解僱:** –

    相關問題