我有3页
- 第1页:菜单
- 第2页:菜单>导航控制器>地图列表视图
- 第3页:菜单>导航控制器>地图
可以在第2页和第3页之间切换,但是当您单击“返回”时,它总是转到第1页,我使用自定义后退按钮执行此操作。
出现以下问题后使用自定义后退按钮后:当我从菜单页面(页面1)转到第2页或第3页时,导航标题会出现,并在不到一秒的时间内消失。这怎么可能?
这些是我正在使用的功能:
private func hideAndAddNewBackButton(){
if backToRoot{
self.navigationItem.hidesBackButton = true
let newBackButton = UIBarButtonItem(title: "Back", style: UIBarButtonItemStyle.Plain, target: self, action: "back:")
self.navigationItem.leftBarButtonItem = newBackButton;
self.title = "Locaties"
}
}
func back(sender: UIBarButtonItem) {
if let viewController2 = storyboard!.instantiateViewControllerWithIdentifier("ViewController2") as? ViewController2{
self.navigationController?.pushViewController(viewController2, animated: true);
}
}
func needBackToRoot(){
backToRoot = true;
}
这是在我的viewDidLoad()中:
var backToRoot:Bool = false;
override func viewDidLoad() {
super.viewDidLoad()
self.hideAndAddNewBackButton();
}
我的开关按钮:
@IBAction func showLijst(sender: AnyObject) {
if let viewController3 = storyboard!.instantiateViewControllerWithIdentifier("Lijst") as? KaartListview{
viewController3.needBackToRoot();
self.navigationController?.pushViewController(viewController3, animated: true);
}
}
在我的情况下问题是创建自定义后退按钮和设置在推送控制器self.navigationController?.navigationBar.topItem?.title =“”我的解决方案是:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.isNavigationBarHidden = false
self.navigationController?.navigationBar.topItem?.title = "SomeTitle"
}
之前我遇到过类似的问题,我使用以下方法修复:
navigationController?.navigationBarHidden = false
在viewDidLoad()
功能
像这样:
override func viewDidLoad() {
super.viewDidLoad()
navigationController?.navigationBarHidden = false
}