2012-08-01 77 views
0

任何人在Xcode 4.4中獲取此警告?當電子郵件撰寫界面的文檔中未駁回在枚舉類型Xcode 4.4警告:案例值不在枚舉類型'MessageComposeResult'(又名'枚舉MessageComposeResult')

案例值「MessageComposeResult」(又名「枚舉MessageComposeResult」)

MFMailComposeResultFailed被包括在結果代碼返回。但是,文檔列出了它,但GCC警告它不是MessageComposeResult中的枚舉。爲什麼?

case MFMailComposeResultFailed:{ 
     //do something here 
    } 
     break; 

這裏是擴展方法,其中這種情況下是所謂的(我有評論此枚舉出禁用警告):

- (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語句。

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!活泉!

+0

展開你的問題,以顯示switch語句和所有大小寫/默認部分。 – 2012-08-01 14:49:41

回答

0

您正在混合錯誤代碼。結果枚舉具有您看到的三個值。

的「MFMailComposeResultFailed」值這個委託方法的誤差範圍內返回:

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 

看這個deocumentation頁面的底部:

MFMailComposeViewController Class Reference 
+0

感謝David H,我真的很無聊!爲了清晰起見,我會用修正更新我的問題。 – 2012-08-01 18:38:10