3

ペン先からロードされたカスタム UITableViewCell があります。次の手順を実行することで、reuseIdentifier を使用してこれをアプリに取り込むことができます。

1) Nib の再利用識別子を「CustomCellIndentifier」として設定します。

2) nib を登録します。

[[self tableView] registerNib:[UINib nibWithNibName:@"CustomCell" bundle:nil] forCellReuseIdentifier:@"CustomCellIndentifier"];

3) tableview:cellForRowAtIndexPath のセルを返します

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
     CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CustomCellIndentifier"];
     return cell;
}

私の質問は、再利用識別子なしでセルを返すにはどうすればよいですか? 小さなテーブルがあり、セルを再利用したくありません (スクロールすると、セルにあるサブビューが台無しになります)。

上記の 3 つの再利用識別子を nil に設定して組み合わせてみましたが、すべてエラーが発生します。

以下でもこれを試しましたが、セルをスクロールするとセルの内容がリセットされ、「再利用されているテーブルセルのインデックスパスがありません」というエラーメッセージが表示されます。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
     CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:nil];
     if (cell == nil) {
           NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
           cell = [topLevelObjects objectAtIndex:0];
     }

     return cell;
}
4

1 に答える 1

-1

これは良い方法ではないと思いますが、要件に応じてこれを使用します:

クラスにinitメソッドを書くCustomCell

- (id)init
        NSArray *nibObjects = [[NSBundle mainBundle] loadNibNamed:@"QuestionOptionCell" owner:self options:nil];
        CustomCell *theEditView = [nibObjects objectAtIndex:0];
        self = theEditView;
        theEditView = nil;
        return self
    }


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
     CustomCell *cell = [[CustomCell alloc] init];
     if (cell == nil) {
           NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
           cell = [topLevelObjects objectAtIndex:0];
     }

     return cell;
}
于 2013-06-13T04:39:56.617 に答える