배열의 목록이 있습니다. 각 배열의 요소는 배열입니다. 나도 알아, 좀 이상해.하지만 필요한거야. 그래서, 나는 가장 깊은 배열의 요소를 대체해야합니다. 나는 이것을 시도했다 :배열 내 배열의 항목 대체
for (int i = 0; i < [myArray count]; i++) {
for (int j = 0; j < [[myArray objectAtIndex:i] count]; j++) {
for (int k = 0; k < [[[myArray objectAtIndex:i] objectAtIndex:j] count]; k++) {
[[[myArray objectAtIndex:i] objectAtIndex:j] replaceObjectAtIndex:k withObject:@"Some_string"];
}
}
}
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI replaceObjectAtIndex:withObject:]: unrecognized selector sent to instance
가있다. 하지만이 요소를 기록 할 수 있습니다. NSLog(@"%@", [NSString stringWithFormat:@"%@",[[[myArray objectAtIndex:0] objectAtIndex:0]objectAtIndex:0]]);
, 괜찮습니다.
무엇을 할 수 있습니까? 당신의 도움을 주셔서 감사합니다.
예. NSMutableArray로 변환해야합니까? 업데이트 : NSMutableArray * myMutArray = [myArray mutableCopy]'에 의해 myArray에서 변경 가능한 배열을 만들지 만 도움이되지 않습니다. – Akki
좀 더 명확하게 표현할 수 있습니까? – LordTwaroog
문제는 내부 배열을 변경할 필요가 있다는 것입니다. 따라서 [myArray mutableCopy] 대신에'myMutArray = [NSMutableArray array]'를 실행 한 다음 myArray를 통해 각 하위 배열에 mutableCopy를 새로운'myMutArray'에 추가하십시오. – mrueg