2016-08-15 32 views
1

我已經創建了一個窗口xib和可可類文件(nswindowcontroller),並且需要使用主窗口中的按鈕操作來顯示來自xib的窗口。如何從xib文件加載並顯示窗口

+2

歡迎來到StackOverflow。請發佈迄今爲止的代碼,以便更好地幫助其他用戶瞭解您的確切問題。 –

回答

1

在你的主NSWindowController:

在接口:

@property (nonatomic, strong) CustomWindowController *windowController; 

在實施:

- (IBAction)didPressOpenWindowButton:(id)sender { 
    CustomWindowController *wc = [[CustomWindowController alloc] init]; 
    [wc showWindow:nil]; 
    [wc.window makeKeyAndOrderFront:nil]; 
    _windowController = wc; 
} 

您IBAction爲連接到您的NSButton在主窗口。

+0

不要工作:-( – mikmikkelsen

+0

@屬性(非原子,強大)CustomWindowController * windowController; – mikmikkelsen

+0

@property(非原子,強大)CustomWindowController * windowController;不工作我喜歡xcode 8,swift 3 – mikmikkelsen