且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Cocoa Mac应用程序中按钮单击打开一个新窗口?

更新时间:2023-01-01 17:35:51

如果你想创建一个新窗口的单独类,这些是步骤:

If you want to create a separate class for New Window, these are the steps:


  1. 创建一个类,它是NSWindowController的子类NewWindowController

  2. 为NewWindowController类创建窗口xib。

  3. 按钮上的代码为:

  1. Create a class which is a sub class of NSWindowController e.g. NewWindowController
  2. Create a window xib for NewWindowController class.
  3. On button click code as:

NewWindowController *controllerWindow = [[NewWindowController alloc] initWithWindowNibName:@"You Window XIB Name"];
[controllerWindow showWindow:self];