本文介绍了如何在HTML页面中创建UItableView.将我的表视图在MFMailComposeViewController中作为邮件正文发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理邮件应用程序.我在一个视图中有一个表格视图,当我在同一视图中单击一个按钮时,我需要加载一个邮件页面.我已经使用MFMailComposeViewController实现了这一点.

I am working on a mail application. I have a table view in a view, I need to load a mail page when I click on a button in the same view. I have implemented this using MFMailComposeViewController.

邮件视图已加载,但我需要将表视图的内容作为邮件正文/邮件正文的附件发送,而不是图标图像.

The mail view loaded, but I need to send the content of the table view as body/ attach of the body of mail, instead of icon image.

-(void)displayComposerSheet 
{
    MFMailComposeViewController *mailpage = [[MFMailComposeViewController alloc] init];
    mailpage.mailComposeDelegate = self;
    [mailpage setSubject:@"summary of chronology"];

    // Set up recipients
    NSArray *toRecipients = [NSArray arrayWithObject:@""]; 
    NSArray *ccRecipients = [NSArray arrayWithObjects:@"",nil]; 
    NSArray *bccRecipients = [NSArray arrayWithObject:@""]; 

    [mailpage setToRecipients:toRecipients];
    [mailpage setCcRecipients:ccRecipients];    
    [mailpage setBccRecipients:bccRecipients];

    //Attach an image to the email
      NSString *path = [[NSBundle mainBundle] pathForResource:@"iCon" ofType:@"png"];
      NSData *myData = [NSData dataWithContentsOfFile:path];
     [mailpage addAttachmentData:myData mimeType:@"image/png" fileName:@"iCon"];

    // Fill out the email body text
    NSString *emailBody = @"";
    [mailpage setMessageBody:emailBody isHTML:NO];

    [self presentModalViewController:mailpage animated:YES];
    //[self.navigationController pushViewController:mailpage animated:YES];
    [mailpage release];
}

推荐答案

将这段代码添加到displayComposerMethod中:

Add to your displayComposerMethod this piece of code:

NSString *emailBody = [self generateHTMLBody];
[mailpage setMessageBody:emailBody isHTML:YES];

和类似的方法:

//assume that you have objects in NSArray* dataArray
- (NSString *)generateHTMLBody {
    NSString *res = @"<HTML><body><table>\n";

    for (int i=0; i < dataArray.count; i++) {
        NSString *tmp = (NSString *)[dataArray objectAtIndex:i];
        res = res = [res stringByAppendingString:@"<tr><td>"];
        res = res = [res stringByAppendingString:tmp];
        res = res = [res stringByAppendingString:@"</td></tr>\n"]; //fix in this line
    }
    res = [res stringByAppendingString:@"</table></body></html>\n"];
    return res;
}
// I didn't test this method.

这当然只是一个示例,generateHTMLBody方法可以并且应该更复杂.

This is of course only an example, and method generateHTMLBody can and should be more sophisticated.

这篇关于如何在HTML页面中创建UItableView.将我的表视图在MFMailComposeViewController中作为邮件正文发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 09:30