0

单击按钮时,我正在使用以下代码

testViewController *myWindowController  = [[testViewController alloc] initWithWindowNibName:@"RecordingsViewController"];

[myWindowController setDelegate:self];
activeModalWindow = [myWindowController window];

[NSApp beginSheet:[myWindowController window]
   modalForWindow:[self window]
    modalDelegate:self
   didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) 
      contextInfo:nil];
[NSApp runModalForWindow:[myWindowController window]];

[[myWindowController window] orderOut: self];

在这个 testViewController 中,我正在使用代码显示警报

NSString *theAlertMessage = [NSString stringWithFormat: @"Already added"];
NSRunAlertPanel(@"", theAlertMessage, @"OK", nil, nil);

但是在单击此警报的确定按钮时。我的警报仍然在屏幕上。请帮忙!

4

2 回答 2

1

使用它作为:

NSAlert *alert = [[NSAlert alloc] init];
[alert setAlertStyle:2];
[alert setMessageText:@"Already added"];

    [alert beginSheetModalForWindow:[(AppDelegate *)[[NSApplication sharedApplication] delegate] window]
                   modalDelegate:self

                  didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
                     contextInfo:nil];
 }

 - (void)sheetDidEnd:(NSAlert *)alert
               returnCode:(int)returnCode contextInfo:(void *)contextInfo
{
    NSLog(@"clicked %d button\n", returnCode);

}

希望它可以帮助你。

于 2013-07-11T06:08:15.237 回答
0

找到了一个替代方案,它完美地工作

NSString *theAlertMessage = [NSString stringWithFormat: @"Already added."];
NSAlert *alert = [[[NSAlert alloc] init] autorelease];
[alert setAlertStyle:NSCriticalAlertStyle];
[alert addButtonWithTitle:@"OK"];
[alert setMessageText:theAlertMessage];
于 2011-07-12T10:03:34.753 回答