Closed cheng-wu closed 9 years ago
Read this post about the view life cycle: http://chrisrisner.com/31-Days-of-iOS--Day-24%E2%80%93The-View-Life-Cycle
This is the order that UIViewController
methods are called when being presented onscreen:
2012-12-27 12:27:35.942 DayTwentyFour[20082:c07] initWithCoder
2012-12-27 12:27:35.947 DayTwentyFour[20082:c07] loadView
2012-12-27 12:27:35.949 DayTwentyFour[20082:c07] viewDidLoad
2012-12-27 12:27:35.949 DayTwentyFour[20082:c07] viewWillAppear
2012-12-27 12:27:35.952 DayTwentyFour[20082:c07] viewWillLayoutSubviews
2012-12-27 12:27:35.952 DayTwentyFour[20082:c07] viewDidLayoutSubviews
2012-12-27 12:27:35.956 DayTwentyFour[20082:c07] viewDidAppear
2012-12-27 12:27:35.942 DayTwentyFour[20082:c07] initWithCoder
2012-12-27 12:27:35.947 DayTwentyFour[20082:c07] loadView
2012-12-27 12:27:35.949 DayTwentyFour[20082:c07] viewDidLoad
Will be only called once for the lifecycle of the viewcontroller. The others may be called multiple times i.e. viewDidAppear will be called every time you switch to the corresponding tab (good place to update your data).
Good point. Also, remember that viewDidAppear
is called each time the view appears when you switching tabs. Depending on the implementation, you may or may not want to load data here. If you expect the data to change frequently (e.g. a twitter stream, you may want to), if it doesn't change frequently (e.g. a RSS feed), you may not need to update here.
Thank you! Get the idea!!!
So in the tutorial video, I saw instructor put the initialized refresh code into viewDidAppear, but in my code, I put it in viewDidLoad since I usually think there are same thing.
Can someone tell me what exact difference between viewDidLoad and viewDidAppear? in what situation, which one is preferred?