将导航栏后退按钮标题重置为默认iOS

时间:2016-10-06 05:12:28

标签: ios swift uinavigationcontroller

我知道我可以设置导航栏后退按钮的标题:

self.navigationItem.backBarButtonItem = UIBarButtonItem(title:"", style:.plain, target:nil, action:nil)

然而,我的应用程序的某些部分我想将其设置回默认文本"返回" (也将使用本地化)。我该怎么做呢?

1 个答案:

答案 0 :(得分:0)

当我在父视图控制器中调用pushViewController后立即放置它时,这个小黑客似乎有用。

但是,我在iPad Pro模拟器上的测试显示,它不仅尝试显示缩写文本,而且后退按钮甚至覆盖了旨在显示在右侧的任何UIButtonBarItem

let backButtonItem = UIBarButtonItem()
backButtonItem.title = "A button title which is much too long to be displayed in the navigation bar, so that iOS will replace this text with localized 'Back' button text."
navigationItem.backBarButtonItem = backButtonItem