ios - 引用 UINavigationBar 上的后退按钮

标签 ios swift uinavigationbar uinavigationitem

我需要引用 UINavigationBarUINavigationItem 中的后退按钮。下图中的 Back 按钮。

Navigation Bar

我没有自定义按钮,因此

navigationItem.backBarButtonItem
navigationItem.leftBarButtonItem

这两个都是零。

有没有办法在不自定义按钮的情况下获取对按钮的引用?

引用:

更新:我的comment可能有助于理解为什么我不想自定义后退按钮。 :)

最佳答案

Documentation这是关于 backBarButtonItem 的:

When this item is the back item of the navigation bar—when it is the next item below the top item—it may be represented as a back button on the navigation bar. Use this property to specify the back button. The default value is a button displaying the navigation item’s title.

所以 backBarButtonItem 默认总是 nil 因为它属于上一个 View Controller 。获得非零引用的唯一方法是自定义它。

但是,如果您只想更改名称,可以在以前的 View Controller 中完成。

关于ios - 引用 UINavigationBar 上的后退按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32076612/

相关文章:

IOS - Android 的 Smack API 库可以用于 IOS 连接到 Ejabberd 服务器吗?

ios - 在 ViewController 中将 API 数据发送到 UITableView

ios - 带有下拉菜单和键盘选项的警报 Controller ? swift 3、Xcode 8、IOS

ios - 每天更新(我的代码有效吗?)

ios - 如何从 GameScene 中的 ViewController 调用方法

iOS 8.4 CFNetwork SSLHandshake 失败 (-9850)

swift - 如何使用 CoreData 保存下载的 CoreML 模型?

ios - UINavigationBar 的奇怪行为

ios - 一个 View Controller 中的自定义导航栏更改

android - windowTranslucentNavigation 问题