我想将主页按钮添加到导航控制器。因此,我创建了下面的课程和分类我的导航控制器。我的按钮出现在我的第一个视图上。当我导航到其他视图(我的图片中的表格视图)时,添加的按钮消失。我正在使用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