I recently had a problem in my app where some of the subviews I was creating in a UIViewController subclass's -awakeFromNib
method were disappearing from the view. After some poking around I found that moving the code I had put in -awakeFromNib
to -viewDidLoad
solved the problem. Seems that -awakeFromNib
gets called only once when the UIViewController is unarchived from the nib, and -viewDidLoad
gets called every time the view is unarchived.
So what's the best practice? It looks like UIViewController's -awakeFromNib
shouldn't be adding any views to the view, that kind of stuff should be done in -viewDidLoad
. Am I understanding this correctly? Or am I more confused than I thought?