如何给 iPhone NSString 换行

发布于 2024-11-30 00:19:05 字数 1582 浏览 1 评论 0原文

我正在尝试将行程作为旅行应用程序的附件发布到 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 的情况下测试它像这样在一行中显示除所有内容之外的所有内容:

事件:在某个博物馆举办的博览会 12/12/2011 12:00 事件:在某个博物馆举办的博览会2
博物馆 13/12/2011 13:00....

我希望它看起来像这样:

事件:在某个博物馆举办的博览会 12/12/2011 12:00
活动:expo2 某博物馆 13/12/2011 13:00
....

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

希望任何人都可以帮助我解决这个问题。 预先感谢! XD

I'm trying to post an itinerary to facebook as an attachment from my travel app, I'm using NSMutableString to append all the itinerary events and dates but I don't know how to give a line break after an event.

This is my code:

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

}

I tried using \n in the last string appended but since the attachment has already a string format with many \ and " when I test it it does not show the attachment text and if I test it without the \n it show everything but all in one line like this:

Event: expo at some museum 12/12/2011 12:00 Event: expo2 at some
museum 13/12/2011 13:00....

And I want it to appear like this:

Event: expo at some museum 12/12/2011 12:00
Event: expo2 at some museum 13/12/2011 13:00
....

EDIT: When I use \n and print with NSLog everything is the way I want but the attachment text does not appear in the facebook dialog screen, somehow the \n affects the whole attachment text.

Hope anybody can help me with this.
Thanks in adevance!! XD

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

孤城病女 2024-12-07 00:19:05

为什么你不使用这个:

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

Why you don't use this:

[description appendString:[NSString stringWithFormat:@"Evento: %@\n", it.event]];
雪花飘飘的天空 2024-12-07 00:19:05

NSString 的换行符是

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

\r ---->回车

Line breaks character for NSString is \r

correct way to use [NSString StringWithFormat:@"%@\r%@",string1,string2];

\r ----> carriage return

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文