开发者

Array value replacement from array within array in iPhone

I have array output like this.

 {
    id = 1;  
    user = {
            name="ABC"
            }
 },  
{

    id = 2;  
    user = {
            name="XYZ"
            }
 },       

I have to change id with number 5 and 6 and name with "asd" and "fgh". My array definition is here.

      myArray=[[NSMutableArray alloc]initWithArray:statuses];

And here is my approach for chaning of "id".

 [[myArray objectAtIndex:0]replaceObjectAtIndex:0 withObject:@"5"];
 [[myArray objectAtIndex:0]replaceObjectAtIndex:0 withObject:@"6"];

But I am getting following acception.

 [__NSC开发者_开发技巧FDictionary replaceObjectAtIndex:withObject:]: unrecognized selector sent to  instance 0x6511810
 Terminating app due to uncaught    exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary replaceObjectAtIndex:withObject:]: unrecognized selector sent to instance 0x6511810'


myArray seems to be NSArray which is Immutable.

How did you declare myArray?

EDIT:

First:

myArray = [statuses mutableCopy];

Second:

[[myArray objectAtIndex:0] setObject:@"5" forKey:@"id"]; 
[[myArray objectAtIndex:1] setObject:@"6" forKey:@"id"];
[[[myArray objectAtIndex:0] objectForKey:@"user"] setObject:@"asd" forKey:@"name"];
[[[myArray objectAtIndex:1] objectForKey:@"user"] setObject:@"fgh" forKey:@"name"]; 
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜