Question

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;
    }
}
Was it helpful?

Solution

Try to insert this line just before the switch:

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

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top