loadView is called each time .view notation is used
I have a view called MyViewController, that I initialize from a xib file.
Its loadView method looks like this:
- (void) loadView
{
[super loadView];
// some initializations
}
I create it from some other view controller like this
-(void) createMyViewController
{
MyViewController *aController = [[MyViewController alloc] initWithNibName: @"MyViewController" bundle: nil ];
self.myController = aController;
[aController release];
CGRect rect = CGRectMake(10, 232, 308, 176);
myController.view.frame = rect;
myController.view.autoresizingMask =
UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleHeight |
UIViewAutoresizingFlexibleTopMargin |
UIViewAutoresizingFlexibleBottomMargin;
[self.view addSubview:graphController.view];
}
I've noticed, that each time .view notation is called, loadView of MyViewController is called. I set t开发者_运维知识库he view property in the xib file, whether File Owner identity is set MyViewController and the view identity is set to MyView. When the view is set it doesn't suppose to call loadView each time.
Please shed some light! I'm fighting this for the whole day already...
Thanks a lot
If you're creating the view in a nib file, you should be using viewDidLoad
, not loadView
.
精彩评论