2011-07-07 19 views
2

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で、問題の根本に似ているはずです。

答えて

3

デバッグ中にこれをxcodeで取得しましたか?もしそうなら、自動的にそれが起こる行にあなたを連れて来るはずです。

もしそうでなければ、SMStandingtableView: cellForRowAtIndexPath:メソッドのどこかのものから見ています。範囲外の一般的な配列のように見えます。助けが必要な場合は、その方法のコードで質問を編集してください。

編集:一般的に、この種のスタックトレースでは、私がを作成したという名前のクラス名/メソッドを見つけようとしています。あなたは6つの項目でNSArrayのを持っているとあなたがいない終了を行い、インデックス6を求め、インデックスのみ0..5包括的に存在する意味

+0

に高すぎる数値を返すされている可能です。私はそれが起こった行に私を連れて行くことができますか? –

+0

これはコードウィンドウで自動的に実行されます。実際にその半迷惑な。ない場合は、 –

+0

が編集にブレークポイントを追加(三角形の中に感嘆符のXcode 4で左ペイン第四ボタンであれば)、エラー/警告リスト内のエラーをクリックしてみてください...それ以上はまだそれを行っていません。 –

1

これはあなたのテーブルビューデリゲートメソッド[SMStandings tableView:cellForRowAtIndexPath:]の内部で起こっている、私が実際にXcodeのコンソールからそれを手に入れたあなたは
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

+0

ええ、エラーの要点を持っています。しかし、私はその配列が追加のインデックスのために割り当てるために定義されている場所を見つけることができないようです。 –

+0

これはおそらく別のオブジェクトから取り出されます。おそらくここの辞書です: 'NSMutableArray * teamsInGroup = [allGroups objectForKey:[allKeys objectAtIndex:indexPath.section]]; NSLog(@ "TEAMS IN GROUP%@@%d"、teamsInGroup、indexPath.row); teamInfo = [teamsInGroup objectAtIndex:indexPath.row]; ' –

関連する問題