【发布时间】:2016-08-21 15:59:43
【问题描述】:
关于这个问题:How to change Back button text from within the child view controller? 我正在寻找一种在使用previousViewController.navigationItem.backBarButtonItem?.title = "New Title" 更改后退按钮标题后刷新导航栏的正确方法。
链接问题的(不太理想?)解决方案:
if let navigationController = self.navigationController {
navigationController.popViewControllerAnimated(false)
navigationController.pushViewController(self, animated: false)
}
编辑:
显然更改图层框架会强制导航栏刷新。我猜这不是解决方案,而是更便宜(?)的解决方法:
if let navigationController = self.navigationController {
navigationController.navigationBar.layer.frame.insetInPlace(dx: 0.1, dy: 0)
navigationController.navigationBar.layer.frame.insetInPlace(dx: -0.1, dy: 0)
}
【问题讨论】:
-
很多时候,当没有直接的方法来做你想做的事情时,这是有充分理由的。后退按钮应该将用户带回到他们来自的地方,并且他们的导航历史不应该被重写。如果您在左上角需要某种其他类型的行为(除了导航返回),则无需使用
backBarButtonItem。 -
在某些特定情况下更改标题可以改善用户体验。以 WhatsApp 为例。
-
假设我从未使用过 WhatsApp。
-
@MJQZ1347 所以我检查了我的 iPhone 上的 WhatsApp,以防我错过了什么——我很肯定他们每次切换到另一个 VC 时只是在创建 UIBarButtonItem;我看不到“刷新”,即在同一个 VC 中更改按钮的标题
-
标签: ios swift cocoa-touch