2012-06-28 1 views
0

Я не могу понять, почему мой didEndSelector не вызывается. Есть идеи?Почему мой didEndSelector в моем NSAlert не называется?

- (void) showMonitorAlertIfNeeded { 

    if (! self.monitorAlert && [self isHideMonitorAlert]) { 

     self.monitorAlert = [MMAlertController monitorAlert]; 

     [[self.monitorAlert window] setTitle: [self applicationName]]; 

     [self.monitorAlert beginSheetModalForWindow: [NSApp keyWindow] 
            modalDelegate: self 
            didEndSelector: @selector(monitorAlertDidEnd:returnCode:contextInfo:) 
             contextInfo: nil]; 


     [[self.monitorAlert window] setLevel: NSScreenSaverWindowLevel]; 

    } 
} 


- (void) monitorAlertDidEnd: (NSAlert *) alert returnCode: (NSInteger) code contextInfo: (id) contextInfo { 

    switch (code) { 
     case NSAlertFirstButtonReturn:{ 
     } 
      NSLog(@"FIRST BUTTON PRESSED"); 
      break; 

     case NSAlertSecondButtonReturn:{ // don't show again. 
      NSLog(@"SECOND BUTTON PRESSED"); 
      [[NSApp delegate]setIsHideMonitorAlert:NO]; 
     } 

     break; 

     default: 
      break; 
    } 
} 
+0

Вы пробовали NSLog вне коммутатора? – paulmelnikow

+0

Хм, просто попробовал это на самом деле. Это называется, любая идея, почему мои инструкции switch не вызываются? – arooo

ответ

1

Попробуйте вставить эту строку непосредственно перед переключателем:

NSLog(@"code: %ld", code); 
+0

Я уже их удалил - не влияет на него. – arooo

+0

Вы зарегистрировали значение, полученное от параметра кода? –

+0

Первая нажатая кнопка и вторая нажатая кнопка не регистрируются. Если я поставлю его вне инструкции switch, это произойдет. – arooo

3

If [MMAlertController monitorAlert], возвращает NSAlert, который был создан с alertWithMessageText:defaultButton:alternateButton:otherButton:informativeTextW‌​ithFormat: то коммутатор должен фактически содержать NSAlertDefaultReturn и NSAlertAlternateReturn. (Если он был создан каким-либо другим способом, то ваши исходные значения switch верны.)