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);

ただし、このアラートの[OK]ボタンをクリックすると。アラートが画面に表示されたままです。助けてください!

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 に答える