【发布时间】:2014-06-16 09:54:20
【问题描述】:
我在NSAlert 对象中添加了两个按钮,目前按钮一个的返回码是1001,而按钮默认为1000。我需要有效地确定在不使用幻数的情况下按下了给定警报中的哪个按钮。否则会变得一团糟。
-(void)showErrorMessage:(NSString*)errorMessage{
NSAlert *alert = [[NSAlert alloc] init];
[alert setMessageText:@"Error"];
[alert setInformativeText:errorMessage];
[alert setAlertStyle:NSCriticalAlertStyle];
[alert addButtonWithTitle:@"Retake test"];
[alert addButtonWithTitle:@"Cancel test"];
[alert beginSheetModalForWindow:window modalDelegate:self didEndSelector:@selector(retakeFingerPrintAlert:returnCode:contextInfo:) contextInfo:nil];
}
- (void)retakeTestAlert:(NSAlert *)alert
returnCode:(int)returnCode
contextInfo:(void *)contextInfo{
NSLog(@"clicked %d button\n", returnCode);
//I want to determine very clearly which button is being pressed in the NSAlert
//I dont want to work with magic numbers
//And thus call the below method dependng on the button clicked
[self onRetakeTest];
}
【问题讨论】:
标签: objective-c macos cocoa-touch cocoa