我有一段代码,当执行时会给我这个错误。而且我相对较新,似乎无法解决问题。NSMutable Array超越界限
错误: 2011-09-06 12:31:06.094 ForceGauge [266:707] CoreAnimation:忽略异常:* - [NSMutableArray的objectAtIndex:]:索引1超出范围[0 .. 0]
-(void)peakCollector:(NSMutableArray *)testarray {
NSUInteger totalRows = [testarray count];
NSMutableArray *percentArray = [[NSMutableArray alloc]initWithObjects:0, nil];
if(forcecontroller.selectedSegmentIndex==0)
testarray = lbData;
else if(forcecontroller.selectedSegmentIndex==1)
testarray = kgData;
else if(forcecontroller.selectedSegmentIndex ==2)
testarray = ozData;
else if(forcecontroller.selectedSegmentIndex ==3)
testarray = newtonData;
for(int i = 0; i< totalRows-1; i++) {
if ([[testarray objectAtIndex:i+1] doubleValue] >= 1.2 * [[testarray objectAtIndex:i] doubleValue]) {
percentArray = [testarray objectAtIndex:i];
DatabaseTable *tableVC = [[DatabaseTable alloc] initWithStyle:UITableViewStylePlain];
[self.navigationController pushViewController:tableVC animated:YES];
if(forcecontroller.selectedSegmentIndex==0)
[tableVC copydatabase:percentArray];
else if(forcecontroller.selectedSegmentIndex==1)
[tableVC copydatabase:kgData];
else if(forcecontroller.selectedSegmentIndex==2)
[tableVC copydatabase:ozData];
else if(forcecontroller.selectedSegmentIndex==3)
[tableVC copydatabase:newtonData];
[tableVC release];
} else {
[analogData removeAllObjects];
}
}
}
'[[NSMutableArray alloc] initWithObjects:0,nil];'。 NSArray只能包含对象,而不能包含原始类型,所以需要将它们包装起来。 '[[NSMutableArray alloc] initWithObjects:[NSNumber numberWithInt:0],nil];' – albertamg
@Bavarious仍然给出同样的错误。 – ilaunchpad
@ila我印象这个问题是在别的地方,这就是为什么我删除了我的答案。不过,我写的东西(和albertamg发表的评论)仍然有效。 – 2011-09-06 17:50:25