[英]Why isn't my didEndSelector in my NSAlert being called?
我不知道为什么我的didEndSelector没有被调用。 有任何想法吗?
- (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;
}
}
如果[MMAlertController monitorAlert]
返回使用alertWithMessageText:defaultButton:alternateButton:otherButton:informativeTextWithFormat:
创建的NSAlert
,则您的开关实际上应包含NSAlertDefaultReturn
和NSAlertAlternateReturn
。 (如果以其他方式创建它,则您的原始switch
值是正确的。)
尝试在开关之前插入以下行:
NSLog(@"code: %ld", code);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.