iOS 为什么在这种情况下 backBarButtonItem 为零

标签 ios swift uinavigationcontroller uinavigationbar uinavigationitem

我有一个嵌入在导航 Controller 中的 View Controller ,在它里面有一个显示另一个 View Controller 的按钮,如下所示:

enter image description here

在第二个 View Controller 中,self.navigationItem.backBarButtonItem 的值为 nil,为什么?

虽然我在运行应用程序时可以看到后退按钮,如下所示:

enter image description here

更新

我读到 View Controller 中的后退按钮是前一个 View Controller 的导航项的责任,更准确地说,它是前一个 View Controller 中的导航项的责任。

所以我尝试在第一个 View Controller 中这样做:

 self.navigationItem.backBarButtonItem!.title = "Wdd"

但我得到了异常,因为 backBarButtonItem 在第一个 View Controller 中也是 nil。

更新2

请看这里

https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/ViewControllerCatalog/Chapters/NavigationControllers.html#//apple_ref/doc/uid/TP40011313-CH2-SW3

有这句话

The navigation item associated with the current view controller provides the content for the center and right positions of the navigation bar. The navigation item for the previous view controller provides the content for the left position

最佳答案

我自己找到了解决方案。

在第一个 VC 中,我这样做是为了加载:

backButton.title = "ddddd"
        self.navigationItem.backBarButtonItem = backButton

它有效

我在这张图片后得到了答案:

enter image description here

关于iOS 为什么在这种情况下 backBarButtonItem 为零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37483011/

相关文章:

ios - QuickBlox iOS 失败,错误代码为 422

ios - 播放其他应用程序的音频

ios - CNContactStoreDidChangeNotification 被多次触发

swift - 这个崩溃错误是我的错还是游戏中心的错

iphone - 自定义 UINavigationController 的编辑按钮?

ios - 如何让容器 View 受到 UINavigationBar 的影响

iphone - iOS:是否可以使 UINavigationBar 更高,并使屏幕下方的其他 View 为 "push"?

iphone - 拥有多个NSPersistentStoreCoordinators是否有意义?

ios - 如何使用 Xcode 在 Swift 中对字符串进行 AES 128 加密并将其作为 POST 发送到服务器?

swift - UINavigationController 释放测试失败?