2013-12-09 45 views
3

我正在使用xCode 5中的應用程序。這是使用故事板的第一個應用程序。我的應用程序以簡單的用戶名/密碼登錄屏幕開始。成功登錄後,我想以編程方式從此登錄視圖切換到標籤頁索引設置爲1的我的標籤欄控制器。從視圖控制器切換到故事板中的選項卡欄控制器xCode

我的UITabBarController沒有自定義類。如果需要,我可以創建一個。有人能幫助我啓動或指引我朝着正確的方向嗎?

回答

2

如何輸入問題可以幫助您解決問題。這裏是我的情況下,有人使用的代碼已經在未來

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil]; 
    UITabBarController *vc = (UITabBarController *)[storyboard instantiateViewControllerWithIdentifier:@"UITabBarController"]; 

    [self presentViewController:vc animated:YES completion:nil]; 
    [vc release]; 
1

如果你只有一個故事板在你的項目,那麼你也可以使用簡單的

self.storyboard 
0

在故事板相同的問題;從您的ViewControllers按鈕(或文件所有者將連接方法)拖到您TabBarVC的Segue。如果您願意,請選擇模式風格和動畫。

爲UITabBarController添加一個新的自定義類,並將其分配給故事板中的TabBarVC。 在它的實現文件中;把self.selectedIndex = 1;

1

要做到這一點,最好的方法是在驗證用戶身份後立即將rootviewController設置爲tabBarcontroller。以下是你如何迅速做到這一點。

let tabBarController = self.storyboard?.instantiateViewControllerWithIdentifier("TabBarController") as! UITabBarController 
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate 
appDelegate.window?.rootViewController = tabBarController 

其中TabBarController是標籤欄控制器的故事板ID。它可以是任何你給它的名字。

相關問題