0

我的應用程序必須有一個啓動屏幕,我執行一些操作,如更新網頁內容。完成該過程後,我會在UITabBarController內顯示整個應用程序界面。在某些時候,應用程序必須返回到此啓動視圖控制器來處理應用程序數據的更新。應用程序設計:UITabBarController裏面UINavigationController

Apple 特別是指出UITabBarController應該是任何應用程序的根視圖控制器。

我正在尋找巧妙的方法在UITabBarController之前呈現UIViewController,而不是將它們都嵌入到UINavigationController中。

我目前有我想避免的設置(UINavigationController - >UITabBarController),因爲它的工作原理和意義。我害怕蘋果不喜歡它,所以我期待着這個主題的一些亮點。

回答

1

但是,我讀過的東西並沒有說明根控制器在應用程序的整個生命週期中都保持不變。怎麼樣...

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 
    self.tabController = (UITabBarController *)[self.window rootViewController]; 

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; 
    self.altController = [storyboard instantiateViewControllerWithIdentifier:@"AlternateController"]; 
    return YES; 
} 

- (void)swapRootControllers { 
    if ([[self.window rootViewController] isKindOfClass:[UITabBarController class]]) { 
     self.window.rootViewController = self.altController; 
    } else { 
     self.window.rootViewController = self.tabController; 
    } 
} 

...假設所有的支持變量聲明和故事板實現。

+0

謝謝。這真的很聰明。我喜歡它。 – tomidelucca 2014-10-01 13:26:04