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

iOS why backBarButtonItem is nil in this scenario

我有一个嵌入导航控制器的视图控制器,里面有一个按钮显示另一个视图控制器,像这样:

在第二个视图控制器中,self.navigationItem.backBarButtonItem的值为nil,为什么?

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

更新

我读到视图控制器中的后退按钮是前一个视图控制器中导航项的职责,更准确地说,它是前一个视图控制器中导航项的职责。

所以我尝试在第一个视图控制器中执行此操作:

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

但是我得到了异常,因为 backBarButtonItem 在第一个视图控制器中也是 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

您可以在第二个控制器中从 Storyboard 添加导航项并设置后退按钮标题。这样 self.navigationItem.backBarButtonItem.title 就不会为 nil.

我自己找到了解决方案。

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

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

有效

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