继承 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 .. 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'
断点位于 teamInfo = 处:
- (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 中得到了这个吗?如果是这样,它应该会自动带您到它发生的线路。
如果不是,从 SMSstanding
的 tableView: cellForRowAtIndexPath:
方法中某处的情况来看,它是发生的。看起来像是通用数组越界问题。如果您需要这方面的帮助,请使用该方法中的代码编辑您的问题。
编辑:一般来说,对于这种堆栈跟踪,我尝试找到一个我制作的类名/方法,然后从那里开始。
关于iphone - iOS NSRangeException、索引越界、NSMutable 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6616128/