关于这个问题:How to change Back button text from within the child view controller?我正在寻找一个合适的方法来刷新导航栏后更改后退按钮标题previousViewController.navigationItem.backBarButtonItem?.title = "New Title"
。如何正确刷新UINavigationBar?
从链接的问题的(不那么理想的?)溶液:
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'。 – nhgrif
在某些特定情况下,更改标题可改善用户体验。以WhatsApp为例。 – MJQZ1347
假设我从未使用过WhatsApp。 – nhgrif