我想知道如何在Cocoa Mac Programming中点击按钮打开一个新窗口.帮我.我正在做一个mac应用程序,需要在特定按钮单击时打开一个新的mac窗口.
iPh*_*eDv 44
如果要为New Window创建单独的类,请执行以下步骤:
在按钮上单击代码为:
NewWindowController *windowController = [[NewWindowController alloc] initWithWindowNibName:@"You Window XIB Name"];
[windowController showWindow:self];
Run Code Online (Sandbox Code Playgroud)Sau*_*abh 13
NSWindowController * wc=[[NSWindowController alloc] initWithWindowNibName:@"your_nib_name"];
[wc showWindow:self];
Run Code Online (Sandbox Code Playgroud)
Han*_*ans 10
Swift 3:在你的故事板中转到WindowController - > Identity inspector - > storyBoardID:填写:mainWindow.然后从您当前的viewcontroller链接故事板上的按钮到以下方法:
@IBAction func newWindow(_ sender: Any) {
let myWindowController = self.storyboard!.instantiateController(withIdentifier: "mainWindow") as! NSWindowController
myWindowController.showWindow(self)
}
Run Code Online (Sandbox Code Playgroud)
- 创建一个类,它是NSWindowController的子类,例如NewWindowController
- 为NewWindowController类创建一个窗口xib.
在按钮上单击代码为:
NewWindowController *controllerWindow = [[NewWindowController alloc] initWithWindowNibName:@"You Window XIB Name"]; [controllerWindow showWindow:self];
是的,但如果此代码在某个函数内部,窗口将关闭.这是解决方案.
在 blah.h
@interface blah : NSObject {
...
NewWindowController *controllerWindow;
...
}
Run Code Online (Sandbox Code Playgroud)
在 blah.m
@implementation
...
-(IBAction)openNewWindow:(id)sender {
controllerWindow = [[NewWindowController alloc] initWithWindowNibName:@"You Window XIB Name"];
[controllerWindow showWindow:self];
}
...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
36671 次 |
| 最近记录: |