使用自定义后退按钮后导航标题消失 [英] Navigation title disappears after use of custom back button
问题描述
我有 3 页
- 第 1 页:菜单
- 第 2 页:菜单 > 导航控制器 > 地图列表视图
- 第 3 页:菜单 > 导航控制器 > 地图
可以在第 2 页和第 3 页之间切换,但是当您单击返回"时,它始终会转到第 1 页,而我使用自定义后退按钮进行了此操作.
It's possible to switch between page 2 and 3 but when you click "Back" it always goes to page 1 and I did this using a custom back button.
使用自定义后退按钮后出现以下问题:当我从菜单页面(第 1 页)转到第 2 页或第 3 页时,导航标题出现,并在不到一秒钟的时间内消失.这怎么可能?
After having used the custom back button once the following problem appears: When I go to page 2 or 3 from the Menu page (Page 1) the navigation title appears and in less than a second it disappears. How is this possible?
这些是我正在使用的功能:
These are the functions I am using:
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() 中:
And this is in my 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 = ""我的解决方案是:
In my case problem was creating custom back button and setting in pushed controller self.navigationController?.navigationBar.topItem?.title = "" My solutions is :
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.isNavigationBarHidden = false
self.navigationController?.navigationBar.topItem?.title = "SomeTitle"
}
这篇关于使用自定义后退按钮后导航标题消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!