New line and returns ignored in setMessageBody

我的未来我决定 提交于 2019-12-21 07:27:22

问题


Am I doing something dumb? I can pre-fill and email ok but the "\r\n" is ignored in the emailBody:

- (void) sendEventInEmail
{
    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
    picker.mailComposeDelegate = self;

    NSString *emailSubject = [eventDictionary objectForKey:EVENT_NAME_KEY];

    [picker setSubject:emailSubject];

    // Fill out the email body text
    NSString *iTunesLink = @"http://itunes.apple.com/gb/app/whats-on-reading/id347859140?mt=8"; // Link to iTune App link
    NSString *content = [eventDictionary objectForKey:@"Description"];
    NSString *emailBody = [NSString stringWithFormat:@"%@\r\nSent using <a href = '%@'>What's On Reading</a> for the iPhone.", content, iTunesLink];

    [picker setMessageBody:emailBody isHTML:YES];

    picker.navigationBar.barStyle = UIBarStyleBlack;

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

Regards

Dave


回答1:


If isHTML set YES \n does not work you either have to set isHTML:NO or use a HTML line break such as <br /> to enter a new line.

<p> </p> inserts a new paragraph which usually means double line break.

Try this with isHTML:YES:

[picker setMessageBody:@"1st line<br />2nd line<br />3rd line<br />and so on..." isHTML:YES]; 

If isHTML:NO just put \n

[picker setMessageBody:@"1st line\n2nd line\n3rd line\nand so on..." isHTML:NO]; 

It will give you this:

1st line
2nd line
3rd line
and so on...




回答2:


Doh... been working too hard and mixing Objective C strings with HTML. Used <p> and </p> tags to fix.

Dave



来源:https://stackoverflow.com/questions/2554250/new-line-and-returns-ignored-in-setmessagebody

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!