我使用 Xcode 6 的 Master Detail Application
模板创建了一个新的 iOS 8 项目。我没有以任何方式更改代码。
如以下屏幕截图所示,在 DetailViewController.m
中设置断点并检查 self.splitViewController
属性时,它返回 nil
。
这是为什么?
根据 Apple UISplitViewController Documentation , self.splitViewController
应该返回最近的 SplitViewController
:
If the receiver or one of its ancestors is a child of a split view controller, this property contains the owning split view controller. This property is nil if the view controller is not embedded inside a split view controller.
最佳答案
不知道您是否曾经想过这个问题,但我刚遇到这个问题,发现出了什么问题,看起来与您的情况相似。
splitViewController 属性在 viewDidLoad 之后才会配置。如果你使用它的代码不小心在 viewDidLoad 之前被触发,那么该值将为 nil。
我注意到在您的代码示例中,configureView 是从 setDetailItem 调用的。如果这是从 prepareForSegue 调用的机会,那么 viewDidLoad 将不会发生,但会导致 configureView 中的 splitViewController 属性值为 nil。所以代码必须在 [super viewDidLoad] 完成后运行。
关于ios - 为什么 self.splitViewController == nil?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27695335/