【发布时间】:2011-09-30 18:17:41
【问题描述】:
在继承一个 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,这似乎是问题的根源。
【问题讨论】:
标签: iphone objective-c nsmutablearray terminate