0

私は、sqlite3 で作成されたデータベースから名前を表示する単純なアプリケーションを開発しようとしています。

エラーが返されます。

2012-08-21 21:10:43.182 NameDatabase[1325:c07] -[UITableView _createPreparedCellForGlobalRow:withIndexPath:] でのアサーションの失敗。/SourceCache/UIKit_Sim/UIKit-1914.84/UITableView.m:6061 2012-08-21 21:10:43.184 NameDatabase[1325:c07] キャッチされていない例外 'NSInternalInconsistencyException' が原因でアプリを終了しています。理由: 'UITableView dataSource はセルを返す必要がありますtableView:cellForRowAtIndexPath:'

問題を解決するために多くのことを試みましたが、アイデアがありません。

これは私が問題を引き起こしていると思う方法です:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"CustomerCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    NameClass *name_class = [self.name_vc objectAtIndex:[indexPath row]];
    cell.textLabel.text = name_class.name;
    //[[cell textLabel] setText:[NSString stringWithFormat:@"%@ ,@%d",name_class.name, name_class.id]];
    return cell;
}
4

1 に答える 1

0

dequeueReusableCellWithIdentifier:CellIdentifier が nil 以外の値を提供しない場合に備えて、tableViewCell を割り当てる必要があります。

    if (!cell) {
    cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
}
于 2012-08-21T19:19:59.183 に答える