我已经使用这种简单的通用方法一段时间了,它适用于基于应用程序的对话框,但是我希望在工作表样式对话框中具有相同的功能,但我很难将它们组合在一起。
根据我理解的文档,OS10.9 及更高版本中唯一不推荐使用的方法是将 NSAlert 类与完成处理程序进程一起使用。从通用方法返回 Bool 似乎几乎是不可能的。
我的代码:
-(BOOL)confirm :(NSString*)questionTitle withMoreInfo:(NSString*)addInfo andTheActionButtonTitle:(NSString*)actionType{
BOOL confirmFlag = NO;
NSAlert *alert = [NSAlert alertWithMessageText: questionTitle
defaultButton:actionType
alternateButton:@"Cancel"
otherButton:nil
informativeTextWithFormat:@"%@",addInfo];
[alert setAlertStyle:1];
NSInteger button = [alert runModal];
if(button == NSAlertDefaultReturn){
confirmFlag = YES;
}else{
confirmFlag = NO;
}
return confirmFlag;
}
The [alert runModal] returns the value I can return.
使用较新的范例,[alert beginSheetModalForWindow:[self window]sheetWindow completionHandler: some_handler] 不允许我在方法结束时更新或返回值。我知道为什么,但是有没有一种我没有想到的方法来实现这一点。
请告诉我如何创建与我一直用于工作表的方法类似的方法。
谢谢三重