NSString新行在邮件中不起作用?

时间:2011-08-30 15:15:33

标签: iphone nsstring mfmailcomposer

我想在用户发送邮件时显示两个UITextView。问题是我希望第二个textview中的文本显示在邮件的新行中。

我已经尝试过使用NSLog,它在那里工作得很好,邮件API是否有问题,或者为什么不能正常工作?

我的代码如下所示:

NSString *desc = descriptionTextView.text;
NSString *ingredients = ingredientsTextView.text;
NSString *emailBody = [NSString stringWithFormat:@"%@\n\n%@", desc, ingredients];
NSLog(@"%@\n\n%@", desc, ingredients);

-(void)displayComposerSheet 

{     MFMailComposeViewController * picker = [[MFMailComposeViewController alloc] init];     picker.mailComposeDelegate = self;

[picker setSubject:titleLabel.text];
NSString *desc = descriptionTextView.text;
NSString *ingredients = ingredientsTextView.text;
NSString *emailBody = [NSString stringWithFormat:@"%@\n\n%@", desc, ingredients];
NSLog(@"%@\n\n%@", desc, ingredients);
[picker setMessageBody:emailBody isHTML:YES];


[self presentModalViewController:picker animated:YES];
[picker release];

}

- (void)viewDidLoad {
titleLabel.text = [recipeData valueForKey:@"title"];
descriptionTextView.text = [recipeData valueForKey:@"description"];
ingredientsTextView.text = [recipeData valueForKey:@"ingredients"];
[super viewDidLoad];

}

1 个答案:

答案 0 :(得分:5)

在邮件编写中只使用html标签,然后就可以正常工作了 使用html <br />标记表示新行。

NSString *desc = descriptionTextView.text;
NSString *ingredients = ingredientsTextView.text;
NSString *emailBody = [NSString stringWithFormat:@"%@ <br/> <br/> %@", desc, ingredients];
// [email setMessageBody:emailBody isHTML:YES]; 
NSLog(@"%@\n\n%@", desc, ingredients);