LoadNibNamed 未设置插座

发布于 2024-12-19 19:37:52 字数 330 浏览 4 评论 0原文

我正在尝试将 NSPopOver 添加到我的应用程序,但仅在运行 10.7 或更高版本时加载它。我已经把弹出窗口、视图控制器和 中加载它

BOOL loaded = [NSBundle loadNibNamed:@"Popovers.xib" owner:self];

在单独的 xib 中查看并从我的应用程序委托的 awakeFromNib 方法 。 xib 加载正常(加载为 YES),但指向 NSPopover 的出口保持为空。在 awakeFromNib 方法中加载 xib 是否有问题?

有趣的是,当我没有在文件名中包含 .xib 扩展名时,它崩溃了。

I'm trying to add an NSPopOver to my app but only load it when running 10.7 or later. I've put the popover, view controller & view in a separate xib and have loaded it with

BOOL loaded = [NSBundle loadNibNamed:@"Popovers.xib" owner:self];

from inside my app delegates' awakeFromNib method. The xib loads ok (loaded is YES) but the outlet, pointing to the NSPopover, remains null. Is there a problem with loading the xib inside the awakeFromNib method?

Interestingly, when I didn't include the .xib extension in the file name it crashed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

完美的未来在梦里 2024-12-26 19:37:52

如果我没猜错的话,NSBundle 的 loadNibNamed:owner: 方法只会加载包,但不会实例化顶级对象。您可以通过使用适当的 NSNib 方法来完成此操作,例如 instantiateNibWithOwner:topLevelObjects:。

我更喜欢通过创建 NSViewController 子类实例来加载 nib:

viewController = [[MyViewController alloc] initWithNibName:@"name" bundle:[NSBundle mainBundle]]

然后在自定义视图控制器的 -(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 方法中实例化 Nib:

[self loadView];

If I got that right, NSBundle's loadNibNamed:owner: method will only load the bundle, but not instantiate the top-level objects. You can do this by using an appropriate NSNib method, e.g. instantiateNibWithOwner:topLevelObjects:.

I prefer to load the nib by creating a NSViewController subclass instance:

viewController = [[MyViewController alloc] initWithNibName:@"name" bundle:[NSBundle mainBundle]]

and then instantiate the Nib inside the custom view controller's -(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil method:

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