2015-01-04 6 views
1

테이블보기에서 이메일을 보낼 수있는 방법이 있습니다.dismissViewControllerAnimated : 작동하지 않습니다.

세포 중 하나가 "문의하기"셀이며, 도청 당할 때마다 MFMailComposeViewController을 사용하여 메일보기 컨트롤러에 연결되지만 문제는 내가 메일보기 컨트롤러를 "취소"또는 "보내기"를 탭할 때입니다. 다시 테이블보기로 돌아 가지 않습니다. "취소"및 "보내기"작업이 작동하지만 메일보기 컨트롤러에 남아 있습니다.

이 관련 방법입니다 :

- (void)sendEmail { 
    // Email Subject 
    NSString *emailTitle = @"Test Email"; 
    // Email Content 
    NSString *messageBody = @"iOS programming is so fun!"; 
    // To address 
    NSArray *toRecipents = [NSArray arrayWithObject:@"[email protected]"]; 

    MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init]; 
    mc.mailComposeDelegate = self; 
    [mc setSubject:emailTitle]; 
    [mc setMessageBody:messageBody isHTML:NO]; 
    [mc setToRecipients:toRecipents]; 

    // Present mail view controller on screen 
    [self presentViewController:mc animated:YES completion:NULL]; 

} 

- (void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error 
{ 
    switch (result) 
    { 
     case MFMailComposeResultCancelled: 
      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; 
    } 

    // Close the Mail Interface 
    [self dismissViewControllerAnimated:YES completion:NULL]; 
} 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

    SettingsControllerSection section = indexPath.section; 

    if (OtherControllerSection == section) { 
     SettingsControllerOtherSection row = indexPath.row; 

     switch (row) { 

      case RateUsController: 
       NSLog(@"rate us was pressed"); 
       break; 

      case ContactUsControllerRow: 
       [self sendEmail]; 
       NSLog(@"send email was pressed"); 
       break; 
     } 
    } 
} 

도와주세요, 감사합니다! mailComposeController에서

+0

MFMailComposeController은 위임 방법, 자동으로 해제하지 않습니다는의 ViewController 직접 – Sandeep

답변

2

방법이처럼 기각 :

[controller dismissViewControllerAnimated:YES completion:NULL]; 
+0

감사를 기각! 나는 당신의 답변을 표시합니다 :) –