0

私はそれをより良い質問にしようとしましょう。uitableviewから電子メール本文を入力する最も良い方法

私はtableviewControllerを持っています。ユーザーがテーブルビューからそのデータを誰かに電子メールで送ることを望む情報が入っています。

その情報を持つ配列を保持することができました。

質問の難しい部分は、メッセージの本文にobjective-c言語を使用している私のテーブルビューのデータをどのように埋め込むのですか?

すべての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]; 
    } 
} 

...あなたのデータのヘッダファイルをインポートすることを忘れないこの1つは、私にとって大きな一歩だったとアプリで面白い(基本)ツールを作成したい場合には、実際には非常に便利です。 客観的なcプログラマーのためのこの典型的なウェブサイトの皆さんに感謝します。

これが結果です。シンプルだが良いスタート方法。

enter image description here

+0

約束通り。ここにスクリーンショットがあります。非常にシンプルなテーブルですが、基本はすべてここにあります。 – Farini

関連する問題