如何将数据传递到iphone中的电子邮件正文中的html表中

时间:2012-12-03 09:40:13

标签: iphone ios mfmailcomposer

我可以创建表格。但是无法将值传递给表。

 - (IBAction)openMail:(id)sender {
    if ([MFMailComposeViewController canSendMail])
    {
        MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
        mailer.mailComposeDelegate = self;
        [mailer setSubject:@"Shopping Cart "];


        NSArray *toRecipients = [NSArray arrayWithObjects:@"fisrtMail@example.com", @"secondMail@example.com", nil];
       [mailer setToRecipients:toRecipients];
       NSString *e=self.phone;
       NSString *f=self.cost;
      //NSString *emailBody = [NSString stringWithFormat:@"%@%@%@%@",e,@"  ",f,@"  has been purchased successfully"];


    NSString *emailBody=@"<html> <table border=1>      <thead><tr><td>Item</td><td>Name</td><td>Qty</td><td>Price</td></tr></thead><tbody><tr><td>1</td><td>1</td><td>One</td><td>One</td></tr><tr><td>2</td><td>Two</td><td>Two</td><td>Two</td></tr><tr><td>3</td><td>Three</td><td>Three</td><td>Three</td></tr><tr><td>4</td><td>Four</td><td>Four</td><td>Four</td></tr></tbody></table> </html> ";


    [mailer setMessageBody:emailBody isHTML:YES];
    [self presentModalViewController:mailer animated:YES];
    //[mailer release];
}

我需要将上面提到的值“e”和“f”传递给html中的表。如何做?你能否回复一下。

3 个答案:

答案 0 :(得分:0)

NSString *emailBody=[NSString stringWithFormat:@"<html> <table border=1>      <thead><tr><td>Item</td><td>Phone</td><td>%@</td><td>Cost</td><td>%@><td>Name</td><td>Qty</td><td>Price</td></tr></thead><tbody><tr><td>1</td><td>1</td><td>One</td><td>One</td></tr><tr><td>2</td><td>Two</td><td>Two</td><td>Two</td></tr><tr><td>3</td><td>Three</td><td>Three</td><td>Three</td></tr><tr><td>4</td><td>Four</td><td>Four</td><td>Four</td></tr></tbody></table> </html> ",e,f];

在上面的代码中,我用电话和费用的值设置e和f,看代码......

我希望这可以帮到你..

答案 1 :(得分:0)

根据我的理解,您需要在'emailBody'中传递var(s)值。如果我是对的,你就像这样格式化你的字符串:

让我们说;

NSString *myHTMLString = @"some value you need to pass";
NSString *emailBody = [NSString stringWithFormat:@"<html><body><table><tr><td>%@</td><tr></table></body>",myHTMLString];

请根据您的HTML格式使用上面。这里,我只举一个例子。

希望这就是你要找的。:)

答案 2 :(得分:0)

请参阅:

NSString *body = [[NSString alloc] initWithFormat:@"<html><body><yourHtmlcode />%@ %@</body></html>", yourVar1, yourVar2];

您也可以使用循环和连接动态创建HTML正文。