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?
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…