私の UITableView では、テーブルの最後のセクションの最後の行に、テーブルの他のすべてとは異なる特別な UITableViewCell をロードします。.xib ファイルにセルを作成し、再利用識別子「endCell」を付けました。セルにアクセスするには、次のようにすればよいと思います。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if ((indexPath.section == [sections count] - 1) && indexPath.row == [[sections objectAtIndex:indexPath.section] count])) {
return [tableView dequeueReusableCellWithIdentifier:@"endCell"];
} //more code for other cells...
インターフェイスビルダーでセル識別子を設定しました。ただし、このコードを実行すると、次のエラーでクラッシュが発生します。
"Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:],..."
このエラーを調査した後、私が見つけた唯一の解決策は、.xib 内に含まれるオブジェクトを保持する配列を介してアクセスすることにより、.xib セルへのポインターを取得することでした。だから私は次のことを試しました:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if ((indexPath.section == [sections count] - 1) && (indexPath.row == [[sections objectAtIndex:indexPath.section] count]) ) {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"endCell"];
if (cell == nil) {
cell = [[UITableViewCell alloc]init];
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"PLNewConversationViewController" owner:self options:nil];
for (id xibItem in topLevelObjects) {
if ([xibItem isKindOfClass:[UITableViewCell class]]){
UITableViewCell *tableViewCell = (UITableViewCell *)xibItem;
if ([tableViewCell.reuseIdentifier isEqualToString:@"endCell"]) {
cell = xibItem;
}
}
}
}
return cell;
} //more code for other cells...
これにより、非常に奇妙な動作が発生します-それが何をしているのかさえ私には明らかではありません-最後のセルが表示されることはなく、テーブルの一番下に到達すると自動的に元のセルに戻るため、無限にスクロールしているように見えますテーブルの上。さまざまなエラーでクラッシュすることがあります。
セルを必要なクラスにアウトレットとして接続し、セルを「return self.endCell ...」として返すだけでこれを回避できましたが、これを行わなくてもセルにアクセスできるはずだと感じています。
誰かが私が間違っていることを見ることができますか?