rootViewController-> tabviewcontroller-> viewController1-> viewController2
按这种顺序,后退按钮可以正常工作,但是当viewController2弹出回到viewController1时,viewController1的后退按钮没有显示,因此我无法返回tabviewcontroller。
可能的原因是什么?感谢您的帮助。
这是我的故事板
//after viewWillAppear
func initNavigation(){
//topItem is self.navigationController?.navigationBar.topItem
guard topItem != nil else {
return
}
//custom letButtonBar just make tabviewcontroller title at left
//other viewcontroller title is "" so position still at center
let leftButton = UIBarButtonItem(title: "", style:UIBarButtonItem.Style.plain, target: self, action: nil)
let attr = [NSAttributedString.Key.foregroundColor:UIColor.white, NSAttributedString.Key.font: UIFont(name: "iconfont", size: UIFont.buttonFontSize)!]
leftButton.setTitleTextAttributes(attr, for: .normal)
leftButton.setTitleTextAttributes(attr, for: .highlighted)
leftButton.setTitleTextAttributes(attr, for: .disabled)
leftButton.tintColor = UIColor.white
leftButton.isEnabled = false
topItem?.backBarButtonItem?.tintColor = UIColor.white
topItem?.setLeftBarButton(leftButton, animated: true)
topItem?.title = ""
}
//tabviewcontroller:
override func initNavigation() {
super.initNavigation()
topItem?.leftBarButtonItem?.title = "tabviewcontrollerTitleAtLeft"
}
//viewcontroller1
override func initNavigation() {
super.initNavigation()
self.navigationItem.title = "viewController1TitleAtCenter"
}
//viewcontroller2
override func initNavigation() {
super.initNavigation()
self.navigationItem.title = "viewController2TitleAtCenter"
}
我尝试了很多次,找到了解决方案,我在viewcontroller1中删除了super.initNavigation(),最后仍然可以正常工作,仍然不知道原因。