Iphone iOS NSRangeException,索引超出边界,NSMutable数组
在导入iPhone应用程序项目后,我的任务是在更新后调试它。不是一个客观的c程序员,我不知道从哪里开始。任何帮助都将不胜感激 以下是调试输出:Iphone iOS NSRangeException,索引超出边界,NSMutable数组,iphone,objective-c,nsmutablearray,terminate,Iphone,Objective C,Nsmutablearray,Terminate,在导入iPhone应用程序项目后,我的任务是在更新后调试它。不是一个客观的c程序员,我不知道从哪里开始。任何帮助都将不胜感激 以下是调试输出: 2011-07-07 15:27:44.333 App[5836:207] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSMutableArray objectAtIndex:]: index 6 beyond bounds [0 ..
2011-07-07 15:27:44.333 App[5836:207] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSMutableArray objectAtIndex:]: index 6 beyond bounds [0 .. 5]'
*** Call stack at first throw:
(
0 CoreFoundation 0x013d0be9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x015255c2 objc_exception_throw + 47
2 CoreFoundation 0x013c66e5 -[__NSArrayM objectAtIndex:] + 261
3 CollegeFootballAlerts 0x00034892 -[SMStandings tableView:cellForRowAtIndexPath:] + 397
...
)
terminate called after throwing an instance of 'NSException'
断点位于teamsInfo=:
- (UITableViewCell *)tableView:(UITableView *)tableView1 cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString* cellIdentifier = @"TeamsInfoCell";
SMStandingsTableViewCell * cell = (SMStandingsTableViewCell *)[tableView1 dequeueReusableCellWithIdentifier:cellIdentifier];
if( cell == nil ){
[[NSBundle mainBundle] loadNibNamed:@"SMStandingsTableViewCell" owner:self options:nil];
cell = standingsTableCell;
standingsTableCell = nil;
}
SMTeamsInfo * teamInfo;
NSMutableArray * teamsInGroup = [allGroups objectForKey:[allKeys objectAtIndex:indexPath.section]];
NSLog(@"TEAMS IN GROUP %@ :: %d", teamsInGroup, indexPath.row);
teamInfo = [teamsInGroup objectAtIndex:indexPath.row];
[[cell teamName] setText:[teamInfo nameEN]];
[[cell teamFlag] setImage:[teamInfo teamFlag]];
NSString * str;
if([segmentedControl selectedSegmentIndex] == 0) { // for conference tab wonconf - lostconf combination is used
str= [NSString stringWithFormat:@"%@",[teamInfo wonconf]];
str = [str stringByAppendingString:@"-"];
str = [str stringByAppendingFormat:@"%@",[teamInfo lostconf]];
}else { // for overall tab wonconf - lostconf combination is used
str= [NSString stringWithFormat:@"%@",[teamInfo wonall]];
str = [str stringByAppendingString:@"-"];
str = [str stringByAppendingFormat:@"%@",[teamInfo lostall]];
}
[[cell currentStanding ]setText:str];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
return cell;
}
和numberOfRowsInSection方法:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSArray * array = [allGroups allKeys];
NSLog(@"NO OF ROWS IN SECTION #%d : %d", section, [[allGroups objectForKey:[array objectAtIndex:section]] count]);
return [[allGroups objectForKey:[array objectAtIndex:section]] count];
}
以及该方法的输出:
2011-07-08 17:46:13.837 App[7513:207] NO OF ROWS IN SECTION #1 : 7
2011-07-08 17:46:13.837 App[7513:207] NO OF ROWS IN SECTION #0 : 6
不知道为什么第1节先来。。。行数与此相反。第0节的值应该是7,第1节的值应该是6,这似乎是问题的根源。您在调试时在xcode中得到这个值了吗?如果是这样的话,它会自动把你带到它发生的地方 如果不是这样,它是从
SMStanding
的tableView:cellforrowatinexpath:
方法中某处事物的外观发生的。看起来像是一个通用数组越界问题。如果您需要这方面的帮助,请使用该方法中的代码编辑您的问题
编辑:一般来说,对于这种堆栈跟踪,我试图找到一个类名/方法,这是我创建的,并从那里开始。这意味着你有一个包含6个项的NSArray,你要求索引6,但它不存在,只存在索引0..5
这发生在您的表视图委托方法中,
[SMStandings tableView:CellForRowatineIndexPath:
,可能您在-(NSInteger)tableView:(UITableView*)表视图行数section:(NSInteger)section中返回的数字太高了,我确实从xcode控制台获得了它。我怎样才能让它把我带到它发生的那一行?它应该在代码窗口中自动完成。事实上,这有点烦人。如果没有,请尝试单击错误/警告列表中的错误(如果在左窗格中的xcode 4第四个按钮中,请使用三角形感叹号)在编辑中添加断点。。。还没有进一步说明。请检查numberOfRowsForSection:方法以确保其正确。看起来您为特定节的数组创建的行太多了。还有一个表视图有两个部分,一个有7行,一个有6行。第一部分显示正确的数据,数组(TeamsingGroup)在调试输出中显示正确数量的条目(7),但在进入第二部分之前只显示6个条目。这里所有的行都正确显示,但当滚动到最后时,我认为它会查找第一节中缺少的行。是的,得到了错误的要点。但我似乎找不到为附加索引定义该数组的位置。它是从另一个对象中提取出来的,可能是这里的字典:
NSMutableArray*teamsInGroup=[allGroups objectForKey:[allKeys objectAtIndex:indexath.section];NSLog(@“组中的团队%@::%d”,TeamsingGroup,indexath.row);teamInfo=[teamsInGroup objectAtIndex:indexath.row]代码>