我正在接收来自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];
答案 0 :(得分:2)
您可以使用此...
NSString * temp = [yourArray componentsJoinedByString:@" "];
注意:如果您需要任何已加入的组件,例如,
:
等,您可以相应地进行修改。如果您想将空间作为连接组件,请使用此@" "(single space), @"\n"(multiple lines)
答案 1 :(得分: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];