我想要在NSMutableArray
替换一个数组对象,从_alertsArray
获取了oldArray
,然后修改值,用newArray
替换oldArray
,但是没实现。
NSArray *oldArray=(NSArray*)[_alertsArray objectAtIndex:[indexPath row]];
NSMutableArray *newArray = [[NSMutableArray alloc] initWithArray:oldArray copyItems:YES];
[newArray replaceObjectAtIndex:3 withObject:@"YES"];
[_alertsArray replaceObjectAtIndex:[indexPath row] withObject:newArray];
解决办法:
NSMutableArray *newArray = [_alertsArray mutableCopy];
[newArray replaceObjectAtIndex:3 withObject:@"YES"];
_alertsArray = newArray;
[_alertsArray replaceObjectAtIndex:[indexPath row] withObject:newArray];