尝试替换已弃用的loadnibnamed:owner [英] Trying to replace deprecated loadnibnamed:owner

查看:510
本文介绍了尝试替换已弃用的loadnibnamed:owner的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要替换已弃用的

[NSBundle loadNibNamed:@"Subscriptions" owner:self];

(只有我可以找到的是等价的)

with this instead (only thing I can find that's equivalent)

[[NSBundle mainBundle] loadNibNamed:@"Subscriptions" owner:self topLevelObjects:nil];

,但对话框弹出并立即消失,而不是保持打开, 。

but the dialog pops up and disappears right away instead of staying open like it was doing with the deprecated call.

这段代码在这样的视图控制器中。

This code is inside a viewcontroller like this.

- (id)init{
    self = [super init];
    if (self) {
        //[NSBundle loadNibNamed:@"Subscriptions" owner:self];

        [[NSBundle mainBundle] loadNibNamed:@"Subscriptions" owner:self topLevelObjects:nil];
    }
    return self;

}

它从appdelegate这样。

and I'm calling it from the appdelegate like this.

SubscriptionsViewController *subscriptionsViewController = [[SubscriptionsViewController alloc] init];
[subscriptionsViewController.window makeKeyAndOrderFront:self];

我遗漏了什么吗?对我来说似乎很直率。

Is there anything I'm missing? It seems straight forward to me.

推荐答案

出现并消失的对话框是可能的对象集合的标志 - 强烈引用将收集的对话框

The dialog appearing and then disappearing is a sign of possible object collection - with a strong reference to the dialog it will be collected and lost.

已弃用的通话保留nib中顶级对象的所有权,但新通话没有。

The deprecated call retained ownership of the top-level objects in the nib, the new call does not.

因此,引用顶级对象的所有者对象的属性必须很强,或者您需要保留顶级对象数组。

Therefore the properties of the owner object that refer to top-level objects must be strong, or you need to keep the top-level objects array. This is contrary to the old recommendation where such properties were weak.

在nib中引用非顶级对象的属性可能仍然很弱。

Properties which reference non-top-level objects in the nib can still be weak.

这篇关于尝试替换已弃用的loadnibnamed:owner的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆