尝试通过presentError
设置一些自定义按钮。 NSLocalizedRecoveryOptionsErrorKey
无效。仅显示标准的“确定”按钮。
NSApp.presentError(NSError(domain: "", code: 0, userInfo: [
NSLocalizedRecoveryOptionsErrorKey: ["Foo", "Bar"]
]))
设置任何其他UserInfo键也没有任何效果。
OS X 10.11是否完全不再支持它?
答案 0 :(得分:2)
NSError *error = [NSError errorWithDomain:@"MyCoolDomain" code:1 userInfo:@{
NSLocalizedDescriptionKey: @"Could Not Post Message",
NSLocalizedFailureReasonErrorKey: @"We could not reach the XING server. Your internet connection seems to be offline.",
NSLocalizedRecoverySuggestionErrorKey: @"You may try again when you are online again.",
NSLocalizedRecoveryOptionsErrorKey: @[@"Try again", @"Cancel"]
}];
NSAlert *alert = [NSAlert alertWithError:error];
alert.informativeText = [error.localizedFailureReason stringByAppendingFormat:@"\n\n%@", alert.informativeText];
[alert beginSheetModalForWindow:self.view.window completionHandler:^(NSModalResponse returnCode) {
}];
试试这个。 来源:https://github.com/Hotel-Reservation-Service/HRSCustomErrorHandling/issues/8
当我遇到这类问题时,我会searching转到其他人的代码/问题。