Bạn đang cố gắng tạo phiên bản NSWindowController
bằng cách khởi tạo nó trong một ngòi bút khác. Tuy nhiên, khi bạn khởi tạo một đối tượng trong một tệp nib, nó được khởi tạo bằng cách gọi -initWithCoder:
.
-initWithCoder:
không phải là bộ khởi tạo được chỉ định là NSWindowController
, vì vậy trường hợp của bạn NSWindowController
không bao giờ thực sự tải ngòi bút.
Thay vì instantiating NSWindowController
dụ của bạn bằng cách đặt nó trong MainMenu.xib
tập tin trong giao diện Builder, tạo ra nó lập trình:
Trong AppDelegate.h:
@class YourWindowController;
@interface AppDelegate : NSObject
{
YourWindowController* winController;
}
@end
Trong AppDelegate.m:
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification*)notification
{
winController = [[YourWindowController alloc] init];
[winController showWindow:self];
}
- (void)dealloc
{
[winController release];
[super dealloc];
}
@end
Trong YourWindowController.m:
@implementation YourWindowController
- (id)init
{
self=[super initWithWindowNibName:@"YourWindowNibName"];
if(self)
{
//perform any initializations
}
return self;
}
@end
Nguồn
2010-04-23 03:54:16
Bạn đang khởi tạo lớp như thế nào? Bạn đang gọi thực hiện siêu của '-initWithWindowNibName:'? –
Lớp con NSWindowController của tôi được khởi tạo trong nib, như tài liệu này nói về: http://developer.apple.com/mac/library/documentation/cocoa/conceptual/ObjCTutorial/06Controller/06Controller.html#//apple_ref/doc/ uid/TP40000863-CH8-SW1 Về cơ bản, MainMenu.xib tạo ra nó –
Tôi gặp phải loại vấn đề tương tự: Tôi không nhận được cuộc gọi đến '- (void) windowDidLoad'. Sau khi đào một số tôi tìm thấy sai lầm của tôi trong lớp con NSWindowController của tôi tôi đã tuyên bố 'cửa sổ' là tài sản.Tôi đã loại bỏ thành viên đó và gọi phương thức 'showWindow:' để có được cửa sổ thành công. – Raviprakash