NSMutableArray *tmpMutArr = [NSMutableArray arrayWithArray:allObjectsArray];
NSLog(@"The content of array is%@",tmpMutArr);
int index;
for (int i=0;i<[tmpMutArr count];i++)
{
if([[tmpMutArr objectAtIndex:i] isKindOfClass:[NSDictionary class]])
{
NSMutableDictionary *tempDict = [tmpMutArr objectAtIndex:i];
if([[tempDict valueForKey:@"Name"] isEqualToString:[NSString stringWithFormat:@"%@", nameString]])
{
index = i;
}
}
}
[tmpMutArr replaceObjectAtIndex:index withObject:[NSDictionary dictionaryWithDictionary:mutDict]];
このコードは、tmpMutArr 内の一致するオブジェクトを置き換えていませんが、代わりに tmpMutArr 内のすべてのオブジェクトを置き換えています。必要なインデックスだけを置き換えるには?
tmpMutArr には置換前のすべてのオブジェクトが含まれていることがわかっているので、インデックスを正しく指定するだけでよいと思います。その方法は?