ios - 在 Obj-C 中使用 Switch 语句

标签 ios objective-c compiler-errors switch-statement

下面是一个 Switch/Case 语句,当无法发送电子邮件时显示错误消息。在大多数情况下,一切似乎都是正确的,但是当我将 UIAlertView 放入 Switch 语句时,我在 Xcode 中收到错误消息:

Xcode error

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/

相关文章:

iphone - 在 ISGL3D 中,我们可以一次只识别一个手势吗?

gcc - libpthread.so.0 : error adding symbols: DSO missing from command line

java - Netbeans 在删除的代码中显示编译错误

ios - 如何在 iOS 中的现有文件夹中查找子文件夹

ios - 如何在 iOS 上使用 Sign In with Google 修复 `The user canceled the sign-in flow.`?

ios - 如何从 UIImagePickerController 获取 1080p 视频?

ios - SpriteKit 中的 CGAffineTransform

objective-c - 请求访问相机胶卷的权限

c++ - Qt QPainterpath.h 错误

ios - 如何使表格 View 快速实用地填充整个 View