为什么MFMailComposeViewController的取消或发送按钮不起作用?

时间:2010-03-22 04:09:13

标签: ios mfmailcomposeviewcontroller

我有问题......

我创建了一个MFMailComposeViewController并显示出来。

但是,“发送”和“取消”按钮都不起作用。

3 个答案:

答案 0 :(得分:6)

您必须在应用程序中加载此代码,

   - (void)mailComposeController:(MFMailComposeViewController*)controller     didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{   
[self dismissModalViewControllerAnimated:YES];
}

试试这个,它可以正常发送和取消按钮。

答案 1 :(得分:1)

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

[controller setSubject:@"Important Data"];

用于html文件邮件

NSString *path=[[NSBundle mainBundle]pathForResource:@"table" ofType:@"html"];
NSFileHandle *readHandle=[NSFileHandle fileHandleForReadingAtPath:path];
htmlString = [[NSString alloc] initWithData: [readHandle readDataToEndOfFile] encoding:NSUTF8StringEncoding];

NSString *emailBody=[NSString stringWithFormat:@"Product Name         %@ \n Company Name       %@  \n Last Updated Date   %@ \n desired data \n %@  ",lblProductName.text,lblCompanyName.text,lblUpdateDate.text,htmlString];

[controller setMessageBody:emailBody isHTML:YES];

[self presentModalViewController:controller animated:YES];

[controller release];

答案 2 :(得分:0)

今天我发现Swift 3.0为这个问题带来了新的功能签名。在此之前,mailComposeController甚至从未被调用过,而邮件(虽然它发送了)只是卡在那里。当我改为下面时,它有效。

  public func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith: MFMailComposeResult, error: Error?) {

    self.dismiss(animated:true, completion: nil)


}