NSWindowController windowDidLoad未调用 [英] NSWindowController windowDidLoad not called

查看:1481
本文介绍了NSWindowController windowDidLoad未调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的Cocoa应用程序使用NSWindowController子类。在nib中设置:

I have a simple Cocoa app using a NSWindowController subclass. In the nib I have set:


  • 文件所有者的类到我的NSWindowController子类


我的NSWindowController子类的init方法被调用(我调用超级),但不管我做什么windowDidLoad从未被调用。

The init method of my NSWindowController subclass is called (I call super), but not matter what I do windowDidLoad is never called.

我必须缺少一些明显的东西,但对于我的生活我不知道是什么。

I must be missing something obvious, but for the life of me I can't figure out what it is.

推荐答案

您尝试创建 NSWindowController 的实例实例化它在另一个笔尖。但是,当您在nib文件中实例化一个对象时,通过调用 -initWithCoder:来初始化它。

You're trying to create the instance of NSWindowController by instantiating it in another nib. However, when you instantiate an object in a nib file, it is initialized by calling -initWithCoder:.

code> -initWithCoder:不是 NSWindowController 的指定初始化程序,因此您的 NSWindowController 实例加载它的nib。

-initWithCoder: is not a designated initializer of NSWindowController, so your instance of NSWindowController never actually loads its nib.

而不是实例化你的 NSWindowController code> MainMenu.xib 文件,以编程方式创建:

Instead of instantiating your NSWindowController instance by placing it in the MainMenu.xib file in Interface Builder, create it programmatically:

AppDelegate.h

@class YourWindowController;
@interface AppDelegate : NSObject
{
    YourWindowController* winController;
}
@end

AppDelegate.m

@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification*)notification
{
    winController = [[YourWindowController alloc] init];
    [winController showWindow:self];
}
- (void)dealloc
{
    [winController release];
    [super dealloc];
}
@end

YourWindowController.m

@implementation YourWindowController
- (id)init
{
    self=[super initWithWindowNibName:@"YourWindowNibName"];
    if(self)
    {
        //perform any initializations
    }
    return self;
}
@end

这篇关于NSWindowController windowDidLoad未调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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