每次使用 .view 表示法时都会调用 loadView

发布于 2024-09-08 09:04:22 字数 995 浏览 1 评论 0原文

我有一个名为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夕色琉璃 2024-09-15 09:04:22

如果您在 nib 文件中创建视图,则应该使用 viewDidLoad,而不是 loadView

If you're creating the view in a nib file, you should be using viewDidLoad, not loadView.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文