Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is self.splitViewController == nil?

I have created a new iOS 8 project using Xcode 6's Master Detail Application template. I have not changed the code in any way.

When setting a breakpoint in DetailViewController.m and inspecting the self.splitViewController property as shown in the following screenshot, it returns nil.

enter image description here

Why is that?

According to the Apple UISplitViewController Documentation, self.splitViewController should return the nearest 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.

like image 975
AlexR Avatar asked Dec 05 '25 13:12

AlexR


1 Answers

Don't know if you ever figured this out, but I just had this issue and found what was wrong and looks similar to your case.

The splitViewController property does not get configured until after viewDidLoad. If by accident your code using it gets triggered before viewDidLoad then the value will be nil.

I notice in your code example that configureView is called from setDetailItem. If that is per chance being called from prepareForSegue then viewDidLoad will not have happened yet resulting in a nil for splitViewController property value inside configureView. So code has to be run after after [super viewDidLoad] has completed.

like image 161
Rory McKinnel Avatar answered Dec 07 '25 03:12

Rory McKinnel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!