我目前有 View Controller A 和 View Controller B。
按下按钮后, View Controller A 将 vc B 推送到其导航 Controller 上:
navigationController?.pushViewController(viewControllerB, animated: true)
VC A 有一个导航栏,其标题为“View Controller A Title”
我想要 VC B 有一个左按钮(后退按钮)和一个标题“View Controller B Title”
目前,当我将 VC B 推到导航 Controller 上时,VC A 的标题会随之出现在左后箭头上,所以看起来像
< View Controller A Title View Controller B Title
如何摆脱 VC A 头衔?
我尝试过设置左栏按钮项目、后栏按钮项目,但都没有成功。
我发现删除该标题的唯一方法是这样做
navigationController?.navigationBar.items?.forEach({ $0.title = "" })
在 VC B 的 viewDidLoad 内部,但是当我单击后退箭头时,VC A 中的标题当然丢失了
对于上面列出的解决方案,我找到的唯一解决方案是在 VC A 的 viewDidAppear 中设置 navigationItem.title,但实际显示的标题大约有 1/2 秒的延迟,这并不理想.
有没有更好的方法来不让这个标题与导航左侧栏项目一起出现?
提前谢谢您!
最佳答案
在 View Controller A 中,只需设置 backBarButtonItem
。
navigationItem.backBarButtonItem = UIBarButtonItem(title: "Back", style: .plain, target: nil, action: nil)
关于swift - 按下后退按钮上没有标题的导航 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50240156/