합성 된 NSMutableArray - theResultArray가 있습니다. 특정 인덱스 (0-49)에 NSNumber 또는 NSInteger 개체를 삽입하고 싶습니다. 웬일인지 나는 나의 배열에 고집 할 어떤 가치도 얻을 수 없다. 모든 인덱스은 nil을 반환 또는 0목표 C 배열에 인덱스에 객체 추가
NSInteger timeNum = time;
[theResultArray insertObject:[NSNumber numberWithInt:timeNum] atIndex:rightIndex];
NSLog(@"The right index is :%i", rightIndex);
NSLog(@"The attempted insert time :%i", time);
NSNumber *testNum = [theResultArray objectAtIndex:rightIndex];
NSLog(@"The result of time insert is:%i", [testNum intValue]);
는 I에있는 viewDidLoad에 theResultsArray을 ALLOC-init을. 시간은 정수입니다. 위의 코드를 여러 가지 조합으로 사용해 보았습니다.
콘솔 출력이 :
StateOutlineFlashCards[20389:20b] The right index is :20
StateOutlineFlashCards[20389:20b] The attempted insert time :8
StateOutlineFlashCards[20389:20b] The result of time insert is:0
시간이 정수인 이유는 왜 정수이고 시간과 동일한 timeNum이 필요합니까? – mk12
나는 객관적인 c와 코코아를 잘 모른다. 아마도 NSInteger 객체가 객관적인 c int보다 더 잘 작동 할 것이라고 생각했습니다. – Bryan
아래 답변에서 모든 변경을가했지만 여전히 정확한 결과를 얻고 있습니다. – Bryan