【问题标题】:How to give line break to NSString iphone如何给 NSString iphone 换行
【发布时间】:2011-08-17 18:57:09
【问题描述】:

我正在尝试将行程作为我的旅行应用程序的附件发布到 Facebook,我正在使用 NSMutableString 来附加所有行程事件和日期,但我不知道如何在事件发生后换行。

这是我的代码:

- (void)postItineraryToWall:(NSArray*)itineraryList{

    NSMutableString *description = [NSMutableString string];

    for (Itinerary *it in itineraryList) {  
        [description appendString:[NSString stringWithFormat:@"Evento: %@", it.event]];   
        [description appendString:[NSString stringWithFormat:@" en %@", it.place]];   
        [description appendString:[NSString stringWithFormat:@" el %@", it.eDate]];     
    }

        FBStreamDialog* dialog = [[[FBStreamDialog alloc] init] autorelease];   dialog.userMessagePrompt = @"Enter your message:";      dialog.attachment = [NSString stringWithFormat:@"{\"name\":\"Conectado desde TravelFan iPhone App\",\"caption\":\"Compartiendo itinerario\",\"description\":\"%@ \",\"media\":[{\"type\":\"image\",\"src\":\"http://www.site.com.mx/content/templates/default/images/logo_travel.jpg\",\"href\":\"http://www.site.com.mx/\"}]}", description];   dialog.actionLinks = @"[{\"text\":\"Obten App!\",\"href\":\"http://www.site.com.mx/\"}]"; [dialog show];

}

我尝试在附加的最后一个字符串中使用 \n,但是由于附件已经是带有许多 \ 和 " 的字符串格式,所以当我测试它时,它不会显示附件文本,如果我在没有 \n 的情况下测试它,它会显示所有内容但像这样在一行中:

活动:某些博物馆的世博会 2011 年 12 月 12 日 12:00 活动:某些博物馆的世博会
博物馆 13/12/2011 13:00....

我希望它看起来像这样:

活动:某博物馆的博览会 2011 年 12 月 12 日 12:00
活动:2011 年 13 月 12 日 13:00 在某博物馆举办的 expo2
....

编辑:当我使用 \n 并使用 NSLog 打印时,一切都是我想要的方式,但附件文本不会出现在 facebook 对话框屏幕中,不知何故 \n 会影响整个附件文本。

希望任何人都可以帮助我。 提前谢谢!!呵呵

【问题讨论】:

    标签: iphone nsstring line-breaks nsmutablestring


    【解决方案1】:

    为什么你不使用这个:

    [description appendString:[NSString stringWithFormat:@"Evento: %@\n", it.event]];
    

    【讨论】:

    • 因为当我使用 \n 时,所有附加文本都没有出现,我认为这与消息已经包含的所有 "" 和 \ 有关。
    【解决方案2】:

    NSString 的换行符是 \r

    [NSString StringWithFormat:@"%@\r%@",string1,string2]的正确使用方法;

    \r ---->回车

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-30
      • 1970-01-01
      • 2011-06-25
      • 2011-01-24
      相关资源
      最近更新 更多