按下按钮时如何制作 NSWindow 弹出窗口

How do I make a NSWindow popup when a button is pressed

我的 cocoa 程序中有一个小小的帮助按钮。我想知道如何在按下时制作一个小的 nswindow 面板弹出窗口,上面有很多文本。我怎样才能做到这一点?按钮叫做help,window可以叫做helpwin

我明白了。我所要做的就是为我的面板创建@属性。然后在我的按钮 IBAction 中,我写了

- (IBAction)help:(id)sender {
    if (![self.helpWin isVisible]) {
        [self.helpWin makeKeyAndOrderFront:sender];
    }
}

而且有效!

根据您的面板需要的复杂程度,您可以简单地弹出一个 NSRunAlertPanel。

-(IB Action)helpPanel:(id)sender
{
    NSInteger choice = NSRunAlertPanel(@"Help", @"The previous string is the titel or main message of your alert panel. This is theft can be longer. You then have three buttons to fill in, the default button and two alternate buttons. With the alternate buttons on 'nil', you get only one button.", @"ok", nil, nil);
}