首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Xcode4.4警告:案例值不在枚举类型'MessageComposeResult‘(也称为'enum MessageComposeResult')中

Xcode4.4警告:案例值不在枚举类型'MessageComposeResult‘(也称为'enum MessageComposeResult')中
EN

Stack Overflow用户
提问于 2012-08-01 22:45:11
回答 1查看 1.4K关注 0票数 0

还有谁在Xcode4.4中得到了这个警告?

案例值不在枚举类型'MessageComposeResult‘(也称为’枚举MessageComposeResult')中

文档中取消邮件撰写接口时返回的结果码中会包含MFMailComposeResultFailed。然而,文档列出了它,但GCC警告说,它不是MessageComposeResult中的枚举。为什么?

代码语言:javascript
复制
    case MFMailComposeResultFailed:{
        //do something here
    }
        break;

下面是调用此案例的扩展方法(我已将此枚举注释掉以禁用警告):

代码语言:javascript
复制
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {

UIAlertView *errormsg = nil;
// Notifies users about errors associated with the interface
switch (result)
{
    case MFMailComposeResultCancelled:
    {
        //Do something, If you need to
        NSString *msgtitle = @"Cancelled Mail";
        NSString *Bodymsg = @"Email Has been Cancelled by USER. You may continue to make modifications to the current attendance data at this point.";
        errormsg = [[UIAlertView alloc] initWithTitle:msgtitle message:Bodymsg delegate:self cancelButtonTitle:@"Close" otherButtonTitles:nil];
    }
        break;
    case MFMailComposeResultSaved:{/*Do nothing at this point*/}
        break;
         //NOTE: MFMailComposeResultFailed is included in Result codes returned when the mail composition interface is dismissed. However the documentation lists it but the GCC warns it is NOT an enum within MessageComposeResult. May be an Apple Bug.
    /*case MFMailComposeResultFailed:{
        NSString *title = @"Unable to Send Mail";
        NSString *msg = @"Failed:\nmessage was not saved or queued, possibly due to an error.\nCheck your mail sent or draft items.";
        errormsg = [[UIAlertView alloc] initWithTitle:title message:msg delegate:self cancelButtonTitle:@"Close" otherButtonTitles:nil];
    }
        break;
       */  
    case MFMailComposeResultSent:{
        NSString *title = @"Mail Sent";
        NSString *msg = @"Attendance Email has been sent. Thank you.";

        errormsg = [[UIAlertView alloc] initWithTitle:title message:msg delegate:self cancelButtonTitle:@"Close" otherButtonTitles:nil];
        //clean up data
        //code here irrelevant
        //set a completed flag for sent email in system

        //display Alert and dismiss the mail composer view here
        UIAlertView *alertView = nil;

        if (result) {
            alertView = [[UIAlertView alloc] initWithTitle:@"AttendanceViewController: viewDidLoad" message:@"updateProgressOfClassInstance FAILED" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        }
        if (alertView != nil) {
            [alertView show];
        }

    }
        break;
    default:
        break;
}
//dismiss view and display any errors here.
[self dismissModalViewControllerAnimated:YES];
if (errormsg != nil) {
    [errormsg show];
}

我希望这能让你们明白。谢谢!

(更新)好的,我的代码中有几个我没有意识到的问题。我修复了它们,下面是结果正确的switch语句。

代码语言:javascript
复制
switch (result)
{
    case MessageComposeResultCancelled:
    {
        //Do something, If you need to!
    }
        break;

    case MessageComposeResultFailed:{
        //Do something else, If you need to!!
    }
        break;

    case MessageComposeResultSent:{
        //Do something user friendly, If you need to!

    }
        break;

    default:
        break;
}

继续在自由世界和stackoverflow上摇摆吧!哇哦!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-08-02 00:13:06

您混淆了错误代码。结果枚举有三个您认为有效的值。

在此委托方法的错误中返回"MFMailComposeResultFailed“值:

代码语言:javascript
复制
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error

看看这个deocumentation页面的底部:

代码语言:javascript
复制
MFMailComposeViewController Class Reference
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11761756

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档