【问题标题】:How to create a UItableView in html page. to mail my table view in MFMailComposeViewController as Body of the mail如何在 html 页面中创建 UItableView。将 MFMailComposeViewController 中的表格视图作为邮件正文邮寄
【发布时间】:2012-01-30 09:04:55
【问题描述】:

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

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

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

【问题讨论】:

    标签: iphone objective-c uitableview mfmailcomposeviewcontroller


    【解决方案1】:

    将这段代码添加到你的 displayComposerMethod 中:

    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 可以而且应该更复杂。

    【讨论】:

    • 很高兴能为您提供帮助。我修复了注释行中的小错误(标签顺序不正确)。
    【解决方案2】:

    此代码有助于通过进行任何更改(如果有)重新加载父页面#refresh

    header("位置:crud_admin.php"); echo 'parent.window.location.reload(true);';

    【讨论】:

    • 这如何回答这个问题?
    猜你喜欢
    • 2011-04-24
    • 2015-04-24
    • 2014-09-11
    • 1970-01-01
    • 2014-03-06
    • 2014-12-10
    • 1970-01-01
    • 2017-06-10
    • 2015-04-22
    相关资源
    最近更新 更多