2011-11-13 59 views
0

好吧,让我试着让它成为一个更好的问题。从uitableview填充电子邮件正文的最佳方法

我有一个tableViewController在我的应用程序中包含一些信息,用户想通过电子邮件向用户提供来自tableview的数据。

我可以保留一个包含该信息的数组。

问题的难点在于如何使用objective-c语言填充来自我的tableview的数据的消息正文?

我是否必须制作一个包含所有html代码的大字符串?还是有更好/更简单的方法呢?即使这只是一张简单的表格,客户也会将其发送给某人。

我想任何解决方案/建议可能是一个伟大的航点,我知道我应该如何处理这个。

+0

你是什么意思的“看起来就像”?你想要的东西就像是表格视图的截图吗?或者你想排列你的项目? –

+2

html + css我在猜测。 – chown

+0

@quixoto:屏幕截图不起作用,因为它不会捕捉到滚动的地方,所以我想布置我的项目。任何想法如何格式?我可以在那里抛出一个数组,但它看起来很丑陋 – Farini

回答

5

我吓坏了! 如果你们想编写一份电子邮件,其中包含你的UITableViewController的数据,那么我就是这么做的。只要记住导入数据头文件...

#import Recipe.h //in the implementation file 
#import Ingredients.h //in the implementation file 
#import <MessageUI/MFMailComposeViewController.h> // this line gotta be in the header file 

-(IBAction)sendmail{ 
MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init]; 
[composer setMailComposeDelegate:self]; 
NSString *recipeTitle = @"<h5>Recipe name: "; 
recipeTitle = [recipeTitle stringByAppendingFormat:recipe.name]; 
recipeTitle = [recipeTitle stringByAppendingFormat:@"</h5>"]; 

NSString *ingredientAmount = @""; 
NSString *ingredientAisle = @""; 
NSString *ingredientTitle = @""; 

NSString *tableFirstLine = @"<table width='300' border='1'><tr><td>Ingredient</td><td>Amount</td><td>Aisle</td></tr>"; 
NSString *increments = @""; 
increments = [increments stringByAppendingFormat:recipeTitle]; 
increments = [increments stringByAppendingFormat:tableFirstLine]; 
int i; 

for (i=0; i < [ingredients count]; i++) { 
    Ingredient *ingredient = [ingredients objectAtIndex:i]; 
    ingredientTitle = ingredient.name; 
    ingredientAmount = ingredient.amount; 
    ingredientAisle = ingredient.aisle; 

    increments = [increments stringByAppendingFormat:@"<tr><td>"]; 
    increments = [increments stringByAppendingFormat:ingredientTitle]; 
    increments = [increments stringByAppendingFormat:@"</td><td>"]; 
    increments = [increments stringByAppendingFormat:ingredientAmount]; 
    increments = [increments stringByAppendingFormat:@"</td><td>"]; 
    increments = [increments stringByAppendingFormat:ingredientAisle]; 
    increments = [increments stringByAppendingFormat:@"</td></tr>"]; 
    if (i == [ingredients count]) { 
     //IF THIS IS THE LAST INGREDIENT, CLOSE THE TABLE 
     increments = [increments stringByAppendingFormat:@"</table>"]; 
    } 
} 

NSLog(@"CODE:: %@", increments); 

if ([MFMailComposeViewController canSendMail]) { 
    [composer setToRecipients:[NSArray arrayWithObjects:@"[email protected]", nil]]; 
    [composer setSubject:@"subject here"]; 
    [composer setMessageBody:increments isHTML:YES]; 
    [composer setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal]; 
    [self presentModalViewController:composer animated:YES]; 
    [composer release]; 
}else { 
    [composer release]; 
    } 
} 

这一个对我来说是巨大的一步,如果你想在你的应用程序来创建有趣的(基本)工具,它实际上是非常有用的。 感谢这个精彩的网站中的每个人都为objective-c程序员。

Andthis是你得到的结果。简单但是开始的好方法。

enter image description here

+0

如承诺。这是截图。非常简单的桌子,但基本都在这里。 – Farini

相关问题