0

I can't figure out why my didEndSelector isn't being called. Any ideas?

 - (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;
    }
}
aroooo
  • 4,726
  • 8
  • 47
  • 81

2 Answers2

3

If [MMAlertController monitorAlert] returns an NSAlert that was created with alertWithMessageText:defaultButton:alternateButton:otherButton:informativeTextW‌​ithFormat: then your switch should actually contain NSAlertDefaultReturn and NSAlertAlternateReturn. (If it was created in any other way then your original switch values are correct.)

Kevin Grant
  • 5,363
  • 1
  • 21
  • 24
1

Try to insert this line just before the switch:

NSLog(@"code: %ld", code);
Bruno Ferreira
  • 942
  • 9
  • 22
  • The first button pressed and second button pressed don't get logged. If I put it outside of the switch statement it does. – aroooo Jun 28 '12 at 00:19
  • What I meant to know was if you logged the value of the code outside the switch. – Bruno Ferreira Jun 28 '12 at 00:21
  • Yes, anything in showMonitorAlertIfNeeded gets logged, anything outside of the switch(code){} gets logged in monitorAlertDidEnd – aroooo Jun 28 '12 at 00:28
  • Edit: Nevermind, that's because we were logging %@ and not %d, I'm gonna try and create a switch with the specific numbers instead. – aroooo Jun 28 '12 at 00:41
  • In my application I have a similar callback function for my NSAlert, the only diference I can see is that instead of code my parameter is called returnCode, but I don't it should make a diference. – Bruno Ferreira Jun 28 '12 at 00:51