开发者

array index for iphone

 NSString *list = @"Norman, Stanley, Fletcher";
NSMutableArray *a2 = [[NSMutableArray alloc] init];
//a2= [list componentsSeparatedByString:@", "];


[a2 addObject:list];
/开发者_开发知识库/NSArray *listItems = [list componentsSeparatedByString:@", "];

NSLog(@"array is  %@",a2);
NSLog(@"array o  %@",a2[0]);

how to get a2[0]=Norman , a2[1]=stanley???


Trying this

   NSArray *listItems = [list componentsSeparatedByString:@", "];
   [a2 addObject:list];
    NSLog(@"array o  %@", [a2 objectAtIndex:0]);


When you create a mutable array you have to add objects to the array. You can't set the mutable array equal to a normal array (its returned by componentsSeparatedByString:)

NSString *list = @"Norman, Stanley, Fletcher";
NSMutableArray *a2 = [[NSMutableArray alloc] init];
[a2 addObjectsFromArray:[list componentsSeparatedByString:@", "]];

NSLog(@"array is  %@",a2);
NSLog(@"array o  %@",[a2 objectAtIndex:0]);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜