下面是一个 Switch/Case 语句,当无法发送电子邮件时显示错误消息。在大多数情况下,一切似乎都是正确的,但是当我将 UIAlertView
放入 Switch 语句时,我在 Xcode 中收到错误消息:
switch (result) {
case MFMailComposeResultCancelled:
NSLog(@"Result: Mail sending canceled");
break;
case MFMailComposeResultFailed:
NSLog(@"Result: Mail sending failed");
UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Sending Failed"
message:@"The email could not be sent."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[message show];
break;
default:
NSLog(@"Result: Mail not sent");
break;
}
当我将代码放入 case
时,为什么会产生错误?
最佳答案
放在括号里:
case MFMailComposeResultFailed: {
NSLog(@"Result: Mail sending failed");
UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Sending Failed"
message:@"The email could not be sent."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[message show];
break;
}
关于ios - 在 Obj-C 中使用 Switch 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9945416/