2014-01-06 52 views
0

我正在接收來自web服務的消息,我保存在NSMutableArray中。如何顯示來自陣列的所有消息的警報

如果我有5條消息在陣列內,我需要在單個警報視圖內顯示它們。

NSString *temp; // Here there is only one message, i want to read all message from Array and feed to alert view. 

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Info" 
          message: temp 
          delegate:nil 
          cancelButtonTitle:@"OK" 
          otherButtonTitles:nil]; 
[alertView show]; 

回答

2

您可以使用此...

NSString * temp = [yourArray componentsJoinedByString:@" "]; 

注:如果您需要任何連接的組件一樣,:等,你可以進行相應的修改。如果你想空間連接的組件,使用此@" "(single space), @"\n"(multiple lines)

+0

非常感謝你,這說明所有的消息,有沒有什麼辦法可以區分所有消息。它顯示像段落... 1234有些事情需要區分1 2 3 4. – user2813740

+0

@ user2813740我認爲,這是顯示最佳方式(1 2 3 4)。如果你指定格式,我會告訴哪一個可能或不可能? – Mani

+0

我的意思是它只是看起來像段落..我想知道如果我可以做一些事情,如>或*在按摩或給顏色替代方式...。所以他們更具可讀性..基本上那些是通知消息給用戶...跳你得到我的觀點..我明白我必須去定製可能...但如果你有任何想法或任何示例代碼... – user2813740

2

這裏是你的代碼

NSArray *alertArr = @[@"alert1", @"alert2", @"alert3", @"alert4", @"alert5"]; 
NSString *temp; 
temp = [alertArr componentsJoinedByString:@"\n"]; 
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Info" 
                message: temp 
                delegate:nil 
              cancelButtonTitle:@"OK" 
              otherButtonTitles:nil]; 
[alertView show]; 
+1

爲什麼不只是'temp = [alertArr componentsJoinedByString:@「\ n」];'? – deanWombourne

+0

感謝您的代碼deanWombourne – larva

相關問題