UIViewController's navigationController is nil when accessed from -viewDidLoad

Originator:cspickert
Number:rdar://14134171 Date Originated:12-Jun-2013
Status:Closed Resolved:Yes
Product:iOS SDK Product Version:iOS 7 beta 1
Classification:Serious Bug Reproducible:Always
 
Summary:

UIViewController's navigationController property should not be nil when accessed from -viewDidLoad.

Steps to Reproduce:

1. Create a UINavigationController and initialize using -init or -initWithNavigationBarClass:toolbarClass: (NOT -initWithRootViewController:).
2. Call -setViewControllers: with a single view controller.
3. Access the view controller's navigationController property from -viewDidLoad.

Expected Results:

The view controller's navigationController property should not be nil.

Actual Results:

The view controller's navigationController property is nil.

Regression:

This bug was not present in the iOS 6 SDK.

Notes:

See sample project here (requires Xcode 5-DP): http://cl.ly/2X343l1B2J0r

The reason the property is not set appears to be because the view controller's view is loaded prematurely (before the navigation controller's view is loaded). Here's some debug output from a breakpoint within -viewDidLoad:

(lldb) p (BOOL) [[[[UIApplication sharedApplication] keyWindow] rootViewController] isViewLoaded]
(BOOL) $0 = NO

Stack trace (edited for readability):

#0 in -[CSViewController viewDidLoad] at CSViewController.m:19
#1 in -[UIViewController loadViewIfRequired] ()
#2 in -[UIViewController view] ()
#3 in -[UINavigationController _transitionForOldViewControllers:newViewControllers:] ()
#4 in -[UINavigationController setViewControllers:animated:] ()
#5 in -[UINavigationController setViewControllers:] ()
#6 in -[CSAppDelegate application:didFinishLaunchingWithOptions:] at CSAppDelegate.m:20

Comments

Seed 3

This issue appears to be resolved in seed 3.

Seed 2

Engineers got back to me asking if the issue is resolved in seed 2. The behavior appears to be the same, however.


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!