4

可能重複:
Action sheet doesn't display when the MFMailComposeViewController's cancel button is tappedMFMailComposeViewController的委託不處理CANCEL按鈕

我根據蘋果提供的代碼示例中我的應用程序中實現標準郵件功能。

我設立委託如下:

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; 
picker.mailComposeDelegate = self; 

,我實現

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

點擊發送按鈕調用的委託,這一切工作正常。但是,點擊取消按鈕不會調用委託,它只是調暗視圖;該應用程序就在那裏掛起。

這裏閱讀類似主題後,我一直在想,認爲可能是關閉屏幕由於某種原因,這超出了我在這一點上理解。請注意,該視圖是以編程方式創建的,並未使用xib文件。

任何想法或意見?

+0

犯罪嫌疑人的委託沒有設置正確,或者你已經在某種程度上「破」的郵件控制器,使得它在內部採取各種錯誤的環境。 –

+0

您使用ARC嗎? – Oscar

回答

8

它可能對你有幫助

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{ 
    // Notifies users about errors associated with the interface 
    switch (result) 
    { 
     case MFMailComposeResultCancelled: 
      //NSLog(@"Result: canceled"); 
      break; 
     case MFMailComposeResultSaved: 
      //NSLog(@"Result: saved"); 
      break; 
     case MFMailComposeResultSent: 
     { 
      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Result" message:@"Mail Sent Successfully" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; 
      [alert show]; 
      [alert release]; 
     } 
      break; 
     case MFMailComposeResultFailed: 
      //NSLog(@"Result: failed"); 
      break; 
     default: 
      //NSLog(@"Result: not sent"); 
      break; 
    } 
    [self dismissModalViewControllerAnimated:YES]; 
} 
9

您需要實現mailComposeController:didFinishWithResult:error委託。並且您將忽略顯示您的郵件視圖的視圖。如果你已經打開了郵件視圖作爲modalView,然後順便解僱,這是 -

- (void)mailComposeController:(MFMailComposeViewController*)controller 
      didFinishWithResult:(MFMailComposeResult)result 
         error:(NSError*)error 
{ 
    if(error) NSLog(@"ERROR - mailComposeController: %@", [error localizedDescription]); 
    [self dismissModalViewControllerAnimated:YES]; 
    return; 
} 
0

嘗試添加甚至簡單的委託:如果委託沒有得到呼籲取消再一個

[picker setDelegate:self]; 
相關問題