分离默认的NSDocument的窗口

来源:互联网 发布:淘宝店员工管理 编辑:程序博客网 时间:2024/06/06 07:02

使用XCode创建Cocoa Application时,选择“Create Document-Based Application”应用时,XCode会默认把主窗口放在Document类中。在代码膨胀后,会导致Document和Window的代码混杂在一起,不方便。


现在,我们将Window的代码放到WindowController类里,减少Document中的Window代码。


1、新建WindowController子类。

@interface WindowController : NSWindowController 


2、删除Document类中的

- (NSString *)windowNibName

- (void)windowControllerDidLoadNib:(NSWindowController *)aController


3、将Document.xib改为MainWindow.xlib


4、在Document类中覆写

- (void)makeWindowControllers {

    // Start off with one document window.

    WindowController *windowController = [[WindowControlleralloc] initWithWindowNibName:@"MainWindow"];

    [self addWindowController:windowController];

}



0 0
原创粉丝点击