swift - 按下后退按钮上没有标题的导航 Controller

标签 swift uinavigationcontroller uibarbuttonitem navigationbar pushviewcontroller

我目前有 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/

相关文章:

ios - Firebase 存储上传在模拟器中有效,但在 iPhone 中无效

swift - 有没有更简单的方法来获取 Swift 中两个值中的较小者

ios - 当我更改 statusBarOrientation 时应用程序生命周期错误

ios - 使用 RxSwift 从 UITableViewCell 发送回调到 UIViewController

iphone - popviewcontroller 没有调用 viewWillappear

iphone - 从导航堆栈中推送/弹出 uiviewcontroller 时如何收到警报

ios - 如何使用 UIBarButtonItem 作为菜单按钮将其作为图像移动到左侧?

iphone - 如何检测 UITableView 是否处于编辑模式?

ios - UIBarButtonItem 在显示两次后不触发选择器

iphone - 当文本字段有输入时启用 UIBarButtonItem