0

iOS 6 シミュレーターで問題なく動作します。iOS 5.1 シミュレーターで初めて実行すると、次の例外が原因でクラッシュします。

*キャッチされない例外 'NSInternalInconsistencyException' が原因でアプリを終了します。理由: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'

これが私のコードです

- (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellIdentifier = @"Cell";

    cell = [theTableView dequeueReusableCellWithIdentifier:cellIdentifier];

    if (cell == nil) {
        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
            [[NSBundle mainBundle] loadNibNamed:@"listTableCell" owner:self options:NULL];
        }
        else{
            [[NSBundle mainBundle] loadNibNamed:@"listTableCell_iPad" owner:self         options:NULL];
        }
        cell = nibLoadCellForListDetails;
    }
    return cell;
}

そして、listTableCell.xib で、ファイルの所有者をテーブル ビュー コントローラーとして設定しました。そして、テーブルビューコントローラーで nibLoadCellForListDetails としてアウトレットを正しく作成しました。

4

2 に答える 2

1

実際にはセルが作成されていないようです。加える:

UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

それ以外の:

cell = [theTableView dequeueReusableCellWithIdentifier:cellIdentifier];
于 2013-04-03T11:09:40.867 に答える
0

このように試してみてください

if (cell == nil) {
    NSArray *nib;
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {

      nib =   [[NSBundle mainBundle] loadNibNamed:@"listTableCell" owner:self options:NULL];
    }
    else{
      nib =  [[NSBundle mainBundle] loadNibNamed:@"listTableCell_iPad" owner:self         options:NULL];
    }
    cell = [nib objectAtIndex:0];
}
于 2013-04-03T11:13:49.230 に答える