在操作表中按取消按钮时关闭邮件控制器视图

时间:2013-03-28 08:48:58

标签: iphone ios objective-c mfmailcomposeviewcontroller

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

-(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];
}

1 个答案:

答案 0 :(得分: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];
}

试试这个