繁体   English   中英

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

[英]How to add a secondary window to a document-based app

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

我的项目包含:

1)ResourceWindow.xib

2)ViewController.xib

3)主板

@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在分配和初始化后立即为nil。

请让我直接说。

谢谢

编辑:

ResourceWindow.xib不包含窗口控制器,而仅包含window。 那是问题吗? 是否可以将自定义对象拖放到xib文件中并将其类更改为NSWindowController的解决方案?

除了Willeke指出的文件名问题之外,在调用showWindow之前,窗口为零。 叹。 我通过子类化NSWindowManager并检查添加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];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM