问题
Due to the keywords "did" and "will" in UIViewController, I have am unsure where to put the code before/after calling super in viewDidLoad and viewWillAppear, in order to make the code run effectively.
For example:
- (void)viewDidLoad
{
[super viewDidLoad];
// Code is here because whatever
// setup in super should been done first
// before we can do anything
}
- (void)viewWillAppear:(BOOL)animated
{
// Code should be here to finish
// whatever we want to do in our view
// before calling super
[super viewWillAppear:animated];
}
This may be applied to didRotate and willRotate as well. Is this correct?
回答1:
Take a look at this answer from here - What does [super viewWillAppear] do, and when is it required?viewwillappear
-do-and-when-is-it-required
As a general rule, you should always call [super viewWillAppear:animated]
first.
来源:https://stackoverflow.com/questions/7901302/placing-code-before-after-calling-super-in-viewdidload-and-viewwillappear