0

カスタムセルの作成中に、次の例外に直面しています。

*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<MasterTableView 0xb612b30> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key address.'

私が使用しているデリゲート関数は次のとおりです。

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

cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) 
{

    NSArray *top=[[NSBundle mainBundle]loadNibNamed:@"CustomCell" owner:self options:nil];// on this line program received SIGABRT

    for (id current in top) {
        if ([current isKindOfClass:[UITableViewCell class]]) {
            cell=(CustomCell *)current;
            break;
        }
    }

}

// Configure the cell...
cell.name.text=@"name";
cell.address.text=@"Address";

return cell;
}

これに加えて、私は次の手順を実行しました。

  1. のファイル所有者CustomCell.xibMasterTableView.h
  2. カスタムセルの出口をMasterTableView.h
  3. 私は2つのためのアウトレットを与えましUILabelCustomCell.h
  4. Cell私はIBのセル識別子として与えました

私はDropboxでプロジェクト全体を共有しました。以下のリンクから入手できます。それも確認できます。何が悪いのか知りたい。

ダウンロードリンク

足りないステップを教えてください。よろしくお願いします。

PS:-プロジェクトでCoreDataを使用しました。コアデータがない場合、この手順で正しい出力が得られますが、このプロジェクトでは得られません。デフォルトのセルで確認しました。それはうまくいきました。

4

3 に答える 3

1

カスタムセルxibで、セルオブジェクトタイプをにCustomcell、FileOwnerタイプをに変更しNSObjectます。次に、セルオブジェクトからアウトレットを設定します。

于 2012-09-03T14:07:59.860 に答える
1

サンプルプロジェクトでコードをコンパイルして実行しましたが、まったく問題なく動作しました。前述のように、InterfaceBuilderですべてが接続されていることを確認してください。

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

    CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {

        NSArray *top = [[NSBundle mainBundle]loadNibNamed:@"CustomCell" owner:self options:nil];

        for (id current in top) {
            if ([current isKindOfClass:[UITableViewCell class]]) {
                cell=(CustomCell *)current;
                break;
            }
        }
    }

    cell.title.text = @"Custom cell labels";

    return cell;
}

編集:

Interface BuilderでIBOutletsを2回接続していますが、参考のために画像を添付しました。それらはファイルの所有者に接続されるべきではありません。ファイルの所有者から接続を削除してください。

また、行が適切なサイズではないことに気付くでしょう。テーブルビューで行サイズを指定する必要があります。

ここに画像の説明を入力してください

于 2012-09-03T14:31:30.300 に答える
0

プロパティからCustomCellのクラスを設定したかどうかを確認します。 ここに画像の説明を入力してください

于 2012-09-03T14:18:32.010 に答える