【问题标题】:New line and returns ignored in setMessageBody在 setMessageBody 中忽略新行和返回
【发布时间】:2010-03-31 15:30:28
【问题描述】:

我在做傻事吗?我可以预先填写并发送电子邮件,但 emailBody 中的“\r\n”被忽略:

- (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];
}

问候

戴夫

【问题讨论】:

    标签: iphone mfmailcomposeviewcontroller


    【解决方案1】:

    如果 isHTML set YES \n 不起作用,您必须设置 isHTML:NO 或使用 HTML 换行符,例如 &lt;br /&gt; 输入 新行 .

    &lt;p&gt; &lt;/p&gt; 插入一个新的段落,这通常意味着双换行。

    试试这个 isHTML:YES:

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

    如果 isHTML:NO 就放 \n

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

    它会给你这个:

    第一行
    第二行
    第三行
    以此类推……

    【讨论】:

      【解决方案2】:

      Doh...一直在努力工作,将 Objective C 字符串与 HTML 混合在一起。使用&lt;p&gt;&lt;/p&gt; 标签修复。

      戴夫

      【讨论】:

      • 我将 HTML 设置为“是”,切换到“否”并且新行正常工作。什么是“和格式代码”?
      • @quantumpotato : 你的解决方案是唯一有效的
      猜你喜欢
      • 2021-01-13
      • 1970-01-01
      • 1970-01-01
      • 2012-08-06
      • 1970-01-01
      • 2021-10-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多