如何将辅助窗口添加到基于文档的应用程序

时间:2016-08-06 20:18:44

标签: objective-c macos nswindowcontroller

我想添加一个包含可以拖放到NSDocuments中的资源的辅助窗口。

我的项目包含:

1)ResourceWindow.xib

2)ViewController.xib

3)Main.storyboard

@interface AppDelegate ()


@property (nonatomic,strong)NSWindowController* wc;
@property  (nonatomic, weak)NSWindow* resourceWindow;
@property (nonatomic, strong)ViewController* vc;


@end

@implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{

    self.wc = [[NSWindowController alloc]initWithWindowNibName:@"ResourceController.xib"];
    self.resourceWindow = [self.wc window];
    [self.wc showWindow:self];
    self.vc = [[ViewController alloc]initWithNibName:nil bundle:nil];
    [self.vc.view setFrame:[self.resourceWindow.contentView bounds]];
    [self.resourceWindow.contentView addSubview:self.vc.view];
}
分配并初始化后,

self.wc.window立即为零。

请直截了当地说明我。

由于

编辑:

ResourceWindow.xib不包含窗口控制器只是一个窗口。那是问题吗?解决方案是将自定义对象拖放到xib文件中并将其更改为NSWindowController吗?

1 个答案:

答案 0 :(得分:0)

除了Willeke指出的文件名问题之外,在调用showWindow之前,windows都是nil。叹。我通过继承NSWindowManager并检查add xib文件再次启动。然后,将文件所有者类设置为SourceWindowController并将代码更改为:

@property (nonatomic,strong)SourceWindowController* wc;
@property  (nonatomic, weak)NSWindow* resourceWindow;


@end

@implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{    
    self.wc = [[SourceWindowController alloc]initWithWindowNibName:@"SourceWindowController"];
    [self.wc showWindow:self.window];
    self.resourceWindow = [self.wc window];