Search code examples
iosuiviewcontrolleruikitviewdidload

UIViewController best practice - loading


I have a simple view controller with some UI outlets. I am using ARC I do additional setup in the viewDidLoad such as setting label properties, if statements to dynamically resize some components, etc. My question is is the viewDidLoadthe best place to place this code? I've posted an example of some of the code I have in the method. Thanks.

self.messageTitleLabel.numberOfLines = 1;
self.messageTitleLabel.adjustsFontSizeToFitWidth = YES;
self.messageTitleLabel.minimumFontSize = 15.0f;
[self someMethodToReframeLabelHeight];

Solution

  • Yes, great place. Recall that in iOS, the system may unload your view due to memory pressure, and so you may get this message again later. Thus, having the code there that adjusts the newly loaded view is perfect.