每次使用 .view 表示法时都会调用 loadView
我有一个名为 MyViewController 的视图,我从 xib 文件初始化它。
它的 loadView 方法如下所示:
- (void) loadView
{
[super loadView];
// some initializations
}
我从其他一些视图控制器创建它,就像
-(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];
}
我注意到的那样,每次调用 .view 表示法时,都会调用 MyViewController 的 loadView 。我在xib文件中设置了视图属性,是否将文件所有者身份设置为MyViewController并将视图身份设置为MyView。设置视图后,它不会每次都调用 loadView 。
请透露一些信息!我已经为此奋斗了一整天......
非常感谢
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 the 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您在 nib 文件中创建视图,则应该使用
viewDidLoad
,而不是loadView
。If you're creating the view in a nib file, you should be using
viewDidLoad
, notloadView
.