LoadNibNamed 未设置插座
我正在尝试将 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我没猜错的话,NSBundle 的 loadNibNamed:owner: 方法只会加载包,但不会实例化顶级对象。您可以通过使用适当的 NSNib 方法来完成此操作,例如 instantiateNibWithOwner:topLevelObjects:。
我更喜欢通过创建 NSViewController 子类实例来加载 nib:
然后在自定义视图控制器的 -(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 方法中实例化 Nib:
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:
and then instantiate the Nib inside the custom view controller's -(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil method: