我一直在尝试将自定义后退按钮添加到正在使用Multi-Storyboard设置的Load栏上创建的导航栏,因此后退按钮不会自动出现,而且我正在尝试使用它的自定义图像。
这是我到目前为止所做的:
class AddFundsMethodTable : UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
override func viewWillAppear(animated: Bool) {
self.styleNavBar()
}
func styleNavBar() {
var newNavBar = UINavigationBar(frame: CGRectMake(0,0, CGRectGetWidth(self.view.frame), 100.0))
newNavBar.tintColor = UIColor.whiteColor()
var navItem = UINavigationItem(title: "Choose a Method")
var backImage = UIImage(named: "backBtn")
var backItem = UIBarButtonItem(image: backImage, style: .Plain, target: self, action: "backButton:")
navItem.leftBarButtonItem = backItem
newNavBar.setItems([navItem], animated: false)
self.view.addSubview(newNavBar)
}
func backButton(sender: UIBarButtonItem) {
self.navigationController?.popToRootViewControllerAnimated(true)
}
}
答案 0 :(得分:0)
在ViewDidLoad
中写下这个:
override func viewDidLoad() {
super.viewDidLoad()
self.styleNavBar()
}