我想創建一個的NSArray填充的NSDictionary的和在控制檯打印所有數組元素的所述第一值。[__NSArrayM objectAtIndex:]:索引2超出範圍[0..1]」
我收到以下錯誤:
Terminating app due to uncaught exception 'NSRangeException', reason:' -[__NSArrayM objectAtIndex:]: index 2 beyond bounds [0 .. 1]' * First throw call stack: (0x30d77e83 0x3b0d46c7 0x30cadd95 0xb93b3 0xb8e03 0x3175ccdd 0x30d42e7f 0x30d42a9b 0x30d40e23 0x30cab471 0x30cab253 0x359e52eb 0x33560845 0xb8abd 0x3b5cdab7)
libc++abi.dylib: terminating with uncaught exception of type NSException
-(void) listOp {
NSDictionary *dictionary;
NSMutableArray *array;
NSNumber *refNum;
int numOp = [_refNum intValue];
self.array = [NSMutableArray arrayWithObjects: self.dictionary, nil];
for (int i = 0; i < numOp; i++){
[self.array insertObject:self.dictionary atIndex:i];
NSDictionary* vardebug = nil;
vardebug = [self.array objectAtIndex:numOp];
NSString *valuekey = [self.dictionary valueForKey: @"key"];
NSLog(@"Valuekey is: %@", valuekey);
}
}
不明白什麼錯誤。
假設numOp = 5。 在for循環的第一次迭代中,self.array在索引5處沒有對象(當您想要獲取vardebug時),它只有2個對象。 – Larme
你想要做什麼? – bsarr007