0

ディクショナリの値に依存する Tableview スタイルのセルを設定する方法を必死に理解しようとしています。ディクショナリは SQLite 行であり、使用するセルを設定する列を設定しました ([タイプ] 列)。これにより、使用するセル スタイルが cellForRowAtIndexPath に通知されます。私の考えでは、このコードは問題なく動作するはずですが、次のエラーが引き続き発生します。

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

どんな助けでも素晴らしいでしょう!どうもありがとう、アンドリュー

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
dictionary = [tableDataSource objectAtIndex:indexPath.row];

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    if ([dictionary objectForKey:@"Type"] == @"1") {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
        cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
        cell.textLabel.numberOfLines = 0;
        cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:17.0];
        cell.detailTextLabel.lineBreakMode = UILineBreakModeWordWrap;
        cell.detailTextLabel.numberOfLines = 0;
        cell.detailTextLabel.font = [UIFont fontWithName:@"Helvetica" size:17.0];
    }
    else if ([dictionary objectForKey:@"Type"] == @"0") {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
        cell.textLabel.numberOfLines = 0;
        cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:12.0];
    }

}
// Configure the cell...
cell.textLabel.text = [dictionary objectForKey:@"Title"];
cell.detailTextLabel.text = [dictionary objectForKey:@"Right_Info"];
return cell; }
4

1 に答える 1

0

NSString2 つのオブジェクトを比較するには、isEqualToString:メソッドを使用する必要があります。演算子を使用==して、2 つのポインターを比較しています。

また、dequeueReusableCellWithIdentifier:すでに のインスタンスを返しているUITableViewCellため、もう一度割り当てようとしないでください。

必要に応じて、Table View プログラミング ガイドをご覧ください。痛くないです。

于 2012-05-24T07:32:06.830 に答える