2014-10-10 45 views
0

我有一個帶有按鈕的視圖的故事公豬。當我點擊那個按鈕時,我應該去一個自定義的UITabBarController,但是所有顯示的都是一個空的選項卡欄。如何在Swift中提供UITabBarController

let tabBar = TabViewController() 
self.presentViewController(tabBar, animated: true, completion: nil) 

在故事板中,我將TabBarController的類設置爲TabViewController。我錯過了什麼?

回答

2

你需要給TabViewController在Interface Builder故事板ID並獲得通過訪問它:

if let tabViewController = storyboard.instantiateViewControllerWithIdentifier("TheAssignedID") as? TabViewController { 
    presentViewController(tabViewController, animated: true, completion: nil) 
} 

你使用剛剛創建TabViewController類的新實例的代碼。不訪問您在Interface Builder中定義的原型。

+1

它的工作,非常感謝。但是我必須添加一個強制轉換,因爲第一行的返回類型是AnyObject。 – Joqus 2014-10-10 20:04:21

+0

我該如何選擇視圖才能加載? – pprevalon 2016-08-23 17:16:18