在我的Xcode项目中,我只是在邮件被取消但是我收到错误(Switch Case在受保护的范围内)时才尝试在邮件用户界面关闭后显示警告显示所有以" case"。
开头的行typedef enum MFMailComposeResult MFMailComposeResult;
switch (result)
{
case MFMailComposeResultCancelled:
[self dismissViewControllerAnimated:YES completion:NULL];
UIAlertView *theAlert = [[UIAlertView alloc] initWithTitle:@"Report Sent"
message:@"Your report has been sent and it will be reviewed. If you are in an emergency, remember to call 911."
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[theAlert show];
NSLog(@"Mail cancelled");
break;
case MFMailComposeResultSaved:
NSLog(@"Mail saved");
break;
case MFMailComposeResultSent:
NSLog(@"Mail sent");
break;
case MFMailComposeResultFailed:
NSLog(@"Mail sent failure: %@", [error localizedDescription]);
break;
default:
break;
}
答案 0 :(得分:3)
在多行情况下放置括号
switch (result)
{
case MFMailComposeResultCancelled: {
[self dismissViewControllerAnimated:YES completion:NULL];
UIAlertView *theAlert = [[UIAlertView alloc] initWithTitle:@"Report Sent"
message:@"Your report has been sent and it will be reviewed. If you are in an emergency, remember to call 911."
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[theAlert show];
NSLog(@"Mail cancelled");
}
break;
case MFMailComposeResultSaved:
NSLog(@"Mail saved");
break;
case MFMailComposeResultSent:
NSLog(@"Mail sent");
break;
case MFMailComposeResultFailed:
break;
default:
break;
}
答案 1 :(得分:1)
试试这个
typedef enum MFMailComposeResult MFMailComposeResult;
switch (result)
{
case MFMailComposeResultCancelled:
{
[self dismissViewControllerAnimated:YES completion:NULL];
UIAlertView *theAlert = [[UIAlertView alloc] initWithTitle:@"Report Sent"
message:@"Your report has been sent and it will be reviewed. If you are in an emergency, remember to call 911."
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[theAlert show];
NSLog(@"Mail cancelled");
break;
}
case MFMailComposeResultSaved:
{
NSLog(@"Mail saved");
break;
}
case MFMailComposeResultSent:
{
NSLog(@"Mail sent");
break;
}
case MFMailComposeResultFailed:
{
NSLog(@"Mail sent failure: %@", [error localizedDescription]);
break;
}
default:
break;
}