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 的情况下测试它,它会显示所有内容但全部在像这样的一行:

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

我希望它看起来像这样:

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

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

希望有人可以帮助我。提前谢谢!!XD

4

2 回答 2

2

为什么你不使用这个:

[description appendString:[NSString stringWithFormat:@"Evento: %@\n", it.event]];
于 2011-08-17T19:04:57.910 回答
0

NSString 的换行符是 \r

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

\r ----> 回车

于 2014-11-25T07:02:09.203 回答