2011-11-28 13 views
1

我需要類似「標籤」(iOS)的可可NSWindow。我有一個「錯誤消息」NSWindow。我使用相同的窗口來顯示許多自定義消息。問題是,如果我釋放窗口,這將關閉,所以我需要在NSDictionary中保留對窗口的引用,並且在close操作中,我將釋放相應的錯誤窗口。NSWindow如何設置和獲取標識符

ErrorWindow *controllerWindow = [[ErrorWindow alloc] initWithWindowNibName:@"ErrorWindow"]; 
[controllerWindow showWindow:self]; 
[controllerWindow setMessageText: message]; 
[controllerWindow setInformationText:info]; 

//If I release the window, it closes. 
[controllerWindow release]; 

回答

0

你可能想繼承NSWindow,這樣你就可以添加你的標籤屬性:

/* MyWindow.h */ 
@interface MyWindow: NSWindow 
{ 
@protected 

    NSInteger _tag; 
} 

@property(assign, readwrite) NSInteger tag; 

@end 

/* MyWindow.m */ 

#import "MyWindow.h" 

@implementation MyWindow 

@synthesize tag = _tag; 

@end 

InterfaceBuilder下,你就那麼可以設置班級的窗戶爲mywindow的,而不是NSWindow。