Кнопка «ОК» для оповещения в приложении Mac не работает - PullRequest
0 голосов
/ 12 июля 2011

При нажатии кнопки я использую приведенный ниже код

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

Но при нажатии кнопки ОКэто оповещение.Мое предупреждение остается на экране.Пожалуйста, помогите!

Ответы [ 2 ]

1 голос
/ 11 июля 2013

Используйте это как:

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

}

Надеюсь, это поможет вам.

0 голосов
/ 12 июля 2011

Нашел альтернативу, отлично работает

NSString *theAlertMessage = [NSString stringWithFormat: @"Already added."];
NSAlert *alert = [[[NSAlert alloc] init] autorelease];
[alert setAlertStyle:NSCriticalAlertStyle];
[alert addButtonWithTitle:@"OK"];
[alert setMessageText:theAlertMessage];
...