Reputation: 21808
I know that viewDidLoad
method may be called multiple times during UIViewController
's lifecycle. But how is that possible? How to make it called more than once not calling it directly? I tried doing it this way:
UIView *view = [[UIView alloc] initWithFrame:self.view.frame];
view.backgroundColor = [UIColor greenColor];
self.view = view;
and whereas my view is actually changed, viewDidLoad
is not called. Can anyone give an example?
Upvotes: 1
Views: 1050
Reputation: 3699
viewWillAppear method is an UIViewController method. Why you shouldn't call directly?
By the way there is no way to do that, while you assign an UIView to your self.view, id you are not doing it in the init or in the loadView or didLoad methods..
the life cycle is that:
Then you present the view and:
if you want to change the view during your uiviewcontroller life cycle you should do:
UIView *view = [[UIView alloc] initWithFrame:self.view.frame];
view.backgroundColor = [UIColor greenColor];
[self viewWillAppear:NO]; //set to yes if you are making some kind of animation
self.view = view;
[self viewDidAppear:NO];
The will disappear and did disappear will be called according to the UIVIewController life cycle.
Upvotes: 0
Reputation: 38728
The first time you access a viewController's view
property the view will be created with loadView
and then you will receive the viewDidLoad
call.
You will not receive the viewDidLoad
call again unless the view is destroyed - this may occur if your viewController goes off screen and UIKit
decides to purge any view's that are not visible. Thus next time you access the view
property it will notice it does not exist and again create one with loadView
and then call viewDidLoad
.
Upvotes: 3