IBOutlets are not setup in awakeFromNib when using storyboards

Originator:kprofic
Number:rdar://18748242 Date Originated:23-Oct-2014 11:47 AM
Status:Open Resolved:No
Product:iOS SDK Product Version:iOS 7.1.2 (11D257), iOS 8
Classification:Serious Bug Reproducible:Always
 
Summary:
When using storyboards to setup iOS application user interface the "awakeFromNib" method is sent to objects unarchived from nib file (eg. UIViewController) however their connections (IBOutlets) are not set yet (nil).

The described problem doesn't occur when app is created using standalone nib files, not storyboards.


Apple documentation fragments that confirm this awakeFromNib storyboard is an unintended behaviour:

NSObject UIKit Additions Reference:
"The nib-loading infrastructure sends an awakeFromNib message to each object recreated from a nib archive, but only after all the objects in the archive have been loaded and initialized. When an object receives an awakeFromNib message, it is guaranteed to have all its outlet and action connections already established."

"Important: Because the order in which objects are instantiated from an archive is not guaranteed, your initialization methods should not send messages to other objects in the hierarchy. Messages to other objects can be sent safely from within an awakeFromNib method."

Additionaly

View Controller Programming Guide -> Resource Management in View Controllers
"[...] The archive is loaded by calling the view controller’s initWithCoder: method. Then, the awakeFromNib method is called on any object that implements that method. You use this method to perform any configuration steps that require other objects to already be instantiated."

ViewController Programming Guide -> Storyboard definition
"[...]As with all objects loaded from a story board, to finish initializing a view controller loaded from a storyboard you override awakeFromNib."

Steps to Reproduce:
Example:
1. Create new iOS project in Xcode (Single View Application)
2. Add a UILabel to RootViewControllers' view in Main.storyboard
3. Create and connect this label to IBOutlet in ViewController.m
4. Add awakeFromNib method in ViewController.m
5. Setup a breakpoint in awakeFromNib
6. Run the application
7. Inspect previously created IBOutlet.

Expected Results:
Properly hooked up my RootViewControllers' IBOutlet having a reference to a UILabel instance. I would also expect all the other NSObjects I put in a nib file to have all the IBOutlets set up when awakeFromNib is called on them.

Actual Results:
IBOutlets are not set up, property value is always nil.
It seems to be set up at later point (it's available in viewDidLoad for instance, however for objects other than UIViewController we can't use viewDidLoad as an entry point for further processing).

Version:
iOS 7.1.2 (11D257), iOS 8

Notes:


Configuration:
iPhone Simulator, iPad 3 Retina

Comments

my issue (http://www.openradar.me/18755803) was closed as a dup of this

my issue doesn't involve storyboards (or I don't believe it to...)

By gradyplayer at Aug. 10, 2015, 9:28 p.m. (reply...)

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!