侵入iPhone應用程序項目後,我負責更新後調試它。不是一個客觀的C程序員,我不知道從哪裏開始。任何幫助,將不勝感激。iOS NSRangeException,超越邊界的索引,NSMutable數組
這裏是調試輸出:
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控制檯中看到它。我怎麼能把它帶到它發生的那一行? –
它應該在代碼窗口中自動執行它。其實半惱人。如果沒有,請嘗試單擊錯誤/警告列表中的錯誤(如果在xcode 4中的左側窗格中第四個按鈕中的感嘆號在三角形中) –
在編輯中添加了斷點......還沒有進一步完成。 –