0

在玩了一段时间的 iOS 之后,我正在开发我的第一个本地 Mac 应用程序。

我试图从菜单项启动一个窗口,但我怀疑我做错了。我连接到这个新窗口上的任何IBAction按钮都会返回错误。

这就是我正在做的事情。从一个菜单项我启动这个:

-(IBAction)displaySAInput:(id)sender{

NSLog(@"Input selected.");
inputSAViewController = [[NSWindowController alloc] initWithWindowNibName:@"InputViewController"];
[inputSAViewController showWindow:self];

这将启动该类InputViewController所拥有的 nib InputViewController。我将InputViewController类设置为继承自NSWindowController.

InputViewController.m我已经测试过IBAction,例如:

-(IBAction)testButton:(id)sender{

NSLog(@"Data recalled?");

}

IBAction通过 Interface Builder 将它连接到一个按钮。一切看起来都很好。

当我构建并打开InputViewController窗口时,我在控制台中收到此错误,然后单击任何内容:

Could not connect the action testButton: to target of class NSWindowController

我进行了广泛的搜索,但我的无知使我无法连接这些点。这个基于与 NSApplication 类似错误的线程看起来很有希望,但我不太明白我需要什么才能使与NSWindowController错误相关的连接发生。

这应该很简单。我错过了什么?

4

2 回答 2

1

你的代码:

-(IBAction)displaySAInput:(id)sender{
    NSLog(@"Input selected.");
    inputSAViewController = [[NSWindowController alloc]
                  initWithWindowNibName:@"InputViewController"];
    [inputSAViewController showWindow:self];
}

请注意,您正在分配/初始化 的通用实例NSWindowController,而不是您实现该testButton:方法的自定义子类。我假设您可能希望将其更改为:

-(IBAction)displaySAInput:(id)sender{
    NSLog(@"Input selected.");
    inputSAViewController = [[InputViewController alloc]
                  initWithWindowNibName:@"InputViewController"];
    [inputSAViewController showWindow:self];
}
于 2012-09-07T15:01:13.073 回答
0

只需事先加载 NSWindow 并使其不可见,当调用 IBAction 时,只需执行以下操作:

[myWindow setIsVisible:YES];
[myWindow setLevel:NSFloatingWindowLevel];

耶!

于 2012-09-07T14:49:58.287 回答