我想將主頁按鈕添加到導航控制器。因此,我創建了下面的課程和分類我的導航控制器。我的按鈕出現在我的第一個視圖上。當我導航到其他視圖(我的圖片中的表格視圖)時,添加的按鈕消失。我正在使用segues推進另一種觀點。UINavigationController右鍵消失
class ThemedNavigationController: UINavigationController {
override func viewDidLoad() {
super.viewDidLoad()
var home = UIBarButtonItem(image: UIImage(named: "home"), style: UIBarButtonItemStyle.Plain, target: self, action: "doneAction")
navigationBar.topItem?.rightBarButtonItem = home
navigationBar.barTintColor = anaRenk
navigationBar.barStyle = .Black
navigationBar.titleTextAttributes = [NSFontAttributeName: UIFont(name: sansSerifName, size: 17)!]
UIBarButtonItem.appearance().setTitleTextAttributes(
[NSFontAttributeName: UIFont(name: sansSerifName, size: 17)!],
forState: .Normal)
}
func doneAction() { // [6]
self.navigationController?.popToRootViewControllerAnimated(true)
}
}
之前我mainViewController沒有導航控制器。相反,每個按鈕都推動新的viewcontrollers有獨立的導航控制器和我的代碼正在工作。如果你能告訴我我該如何解決這個問題,我將不勝感激。
這可能幫助:http://stackoverflow.com/questions/6389094/adding-same-button-to-all-view-controllers-in-uinavigationcontroller?rq=1 – Masa 2015-02-07 17:13:14