Last active
June 12, 2016 20:39
-
-
Save thornpig/27676620e2a2b3f89bb9 to your computer and use it in GitHub Desktop.
initWithNibName: vs initWithCoder: for UIVIewController
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [UIViewController initWithNibName:] is only used when the view controller is created directly in code instead of in storyboard. | |
| The nib file with the nib name if actually for the view of the controller (in fact there is no option for view controller when creating new User Interface file in Xcode), | |
| so unarchiving the nib file will call | |
| [UIView initWithCoder:] instead of [UIViewController initWithCoder:]. | |
| The unarchiving will only be triggered when the view property | |
| of the view controller is accessed for the first time, because [UIView initWithCoder:] is called by [UIViewController loadView]. | |
| On the other hand, when UIViewController is created in storyboard, either automatically by storyboard or manually by calling | |
| [UIStoryboard instantiateViewControllerWithItentifier:], | |
| [UIViewController initWithCoder:] will be called to unarchive the view controller object from the storyboard. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment