1

我有一个包含四个部分的表格视图。其中一个部分的单元格包含电子邮件地址。当我单击该单元格时,我打开邮件视图控制器。现在,当我单击导航栏上的取消按钮时,会出现一个包含三个按钮的操作表。这三个按钮之一是取消按钮。现在,当我单击操作表的取消按钮时,我想返回表格视图。我已经尝试了所有可能的方法,包括

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

MFMailComposeViewController委托 方法。

请帮帮我。这是我的代码:

if(indexPath.section == 2)
    {

if([MFMailComposeViewController canSendMail])

{

MFMailComposeViewController *mailcontroller = [[MFMailComposeViewController alloc]init];
               [mailcontroller.mailComposeDelegate self];
               [mailcontroller setToRecipients:[[NSArray alloc]initWithObjects:record.contactemail, nil]];
               [self presentViewController:mailcontroller animated:YES completion:nil];

}

}

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

{

[self dismissViewControllerAnimated:YES completion:nil];
}
4

1 回答 1

3

首先在您的文件中添加这两个委托,.h如下所示...

@interface yourViewController : UIViewController<
MFMessageComposeViewControllerDelegate, MFMailComposeViewControllerDelegate>{
   ///your code..
}

并像下面这样给自己代表...

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

并尝试我的这种方法...

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
    if (result == MFMailComposeResultSent) 
    {
        NSLog(@"\n\n Email Sent");
        [AppDelegate showAlert:@"Email Sent"];

    }
    if([self respondsToSelector:@selector(dismissViewControllerAnimated:completion:)])
        [self dismissViewControllerAnimated:YES completion:nil];
    else
        [self dismissModalViewControllerAnimated:YES];
//    [self dismissViewControllerAnimated:YES completion:nil];
}

试试这个

于 2013-03-28T08:57:06.233 回答