0

I am receiving messages from web service which i saves in NSMutableArray.

if i have 5 messages inside array i need to show all of them within single alert view.

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];
Gavin
  • 8,204
  • 3
  • 32
  • 42
user2813740
  • 517
  • 1
  • 7
  • 29

2 Answers2

2

You may use this...

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

Note: If you need any joined component like , : etc, You can modify accordingly. If you want space as joined component, use this @" "(single space), @"\n"(multiple lines)

Mani
  • 17,549
  • 13
  • 79
  • 100
  • thank you very much, this shows all messages, is there any way i can differentiate all messages. it shows like paragraph… 1234 some things to diff between 1 2 3 4. – user2813740 Jan 06 '14 at 11:54
  • @user2813740 I think, this is best way to show(1 2 3 4). If you specify format, i'll tell which is either possible or not? – Mani Jan 06 '14 at 12:00
  • i mean it just looks like paragraph.. i was wondering if i can do some thing like > or * in front of massages or give colour alternate way…. so that they are more readable.. basically those are notification message to user… hop u got my point.. i understand i have to go for custom may be … but if you have any idea or any sample code... – user2813740 Jan 06 '14 at 12:24
  • @user2813740 I didn't understand about your paragraph style. just show example text(para style). see this post to coloring string. http://stackoverflow.com/questions/14287386/change-string-color-with-nsattributedstring. Just try with NSAttributedString, it may not work, I didn't try this. Because type of `initWithTitle:....` vary with `NSAttributedString`. – Mani Jan 06 '14 at 12:27
2

here is your code

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];
larva
  • 4,687
  • 1
  • 24
  • 44