0

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

 - (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中的表格。怎么做?你能回复一下吗。

4

3 回答 3

0

看:

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

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

于 2012-12-03T10:00:06.670 回答
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 设置为 Phone 和 cost 的值,请参见代码...

我希望这对你有帮助..

于 2012-12-03T09:49:17.273 回答
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 格式使用上面的内容。这里,我只是给你一个例子。

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

于 2012-12-03T09:49:38.913 回答