我有3页
- Page 1: Menu
- Page 2: Menu > Navigation Controller > Map listview
- Page 3: Menu > Navigation Controller > Map
可以在第 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);
}
}
最佳答案
在我的案例中,问题是创建自定义后退按钮并在推送 Controller 中进行设置 self.navigationController?.navigationBar.topItem?.title = "" 我的解决方案是:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.isNavigationBarHidden = false
self.navigationController?.navigationBar.topItem?.title = "SomeTitle"
}
关于ios - 使用自定义后退按钮后导航标题消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32455033/