2
이 코드는 오류를 발생 시키지만 정확해야합니다.NSMutableArray에 NSNumber 객체 추가
(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSNumber *rowNumber = [[NSNumber alloc] initWithInt:indexPath.row];
[genreArray addObject:rowNumber];
[self.tableView reloadData];
}
genreArray
는 NSMutableArray
그러나 셀에 터치에 나는이 오류
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[__NSCFArray insertObject:atIndex:]: mutating method sent to immutable object'
*** First throw call stack:
(0x1c9c012 0x10d9e7e 0x1c9bdeb 0x1d1c9a5 0x1d1c8b0 0x7b4c 0xcd285 0xcd4ed 0xad75b3 0x1c5b376 0x1c5ae06 0x1c42a82 0x1c41f44 0x1c41e1b 0x1bf67e3 0x1bf6668 0x1dffc 0x271d 0x2645)
libc++abi.dylib: terminate called throwing an exception
이 사람이 작동하지 않는 이유를 생각을 구하셨 수있다? 배열은 불변이기 때문에
으로 수행해야합니다 당신은 변경할 수있는' NSNumber * rowNumber = [[NSNumber alloc] initWithInt : indexPath.row];'NSNumber * rowNumber = @ (indexPath.row); ' – graver
'genreArray = [[NSMutableArray alloc] init];을 할당 했습니까 – laxonline
문제는 NSMutableArray로 할당했지만, 다음과 같이 썼습니다 : genreArray = someOtherArray; someOtherArray는 배열이며 변경 가능한 배열이 아닙니다. 이제 나는 그것을 [NSMutableArray arrayWithArray : someOtherArray]와 함께 할당한다. 그게 효과가있어! – Wed