How to create a UItableView in html page. to mail my table view in MFMailComposeViewController as Body of the mail

可紊 提交于 2019-12-24 16:25:36

问题


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

回答1:


Add to your displayComposerMethod this piece of code:

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

and method like this:

//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.

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




回答2:


This code helps to reload the parent page by making any changes(if there)#refresh

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



来源:https://stackoverflow.com/questions/9061479/how-to-create-a-uitableview-in-html-page-to-mail-my-table-view-in-mfmailcompose

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!