1

NSRangeExceptionの謎を解くことができません。

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [_countyList count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"Inside masterview cellforrowatindexpath.\n");

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    // Configure the cell...
    cell.textLabel.text = [_countyList objectAtIndex:indexPath.row];

    return cell;
}

例外は、1をnumberOfSectionsInTableView返すとスローされます(1つのセクションがあるはずです)が、0のセクションを返すと、例外はスローされません(データも表示されません)。コードが実行されると、が呼び出されることはありませんcellForRowAtIndexPath。デバッガーによってメイン関数に移動しますが、NSArrayにアクセスしている場所が一生わかりません。
ヘルプやデバッグのヒントをいただければ幸いです...

4

1 に答える 1

2

ストーリーボードを使用している場合は、この投稿を確認してください。

iOSXcode4.2マスター-NSRangeExceptionをスローする詳細アプリケーションテンプレート

あなたが説明している問題はそれに似ています。

于 2011-12-13T04:59:00.190 に答える