したがって、セクションと行を持つ tableView があり、カスタム セル クラスを使用しています。カスタム セルには、画像ビューといくつかのラベルがあります。テーブルビューは正常に機能し、検索は機能しますが、検索ではカスタムセルクラスにあるラベルが表示されず、正しい画像を持つ imageView のみが表示されます。特に画像はまだ表示されていますが、ラベルは表示されていないため、これがなぜなのか非常に混乱しています。ここにいくつかのコードがあります。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//TODO: problem with search view controller not displaying labels for the cell, needs fixing
JSBookCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if(cell == nil) {
cell = [[JSBookCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
JSBook *book = nil;
//uses the appropriate array to pull the data from if a search has been performed
if(tableView == self.searchDisplayController.searchResultsTableView) {
book = self.filteredTableData[(NSUInteger)indexPath.section][(NSUInteger)indexPath.row];
}
else {
book = self.books[(NSUInteger)indexPath.section][(NSUInteger)indexPath.row];
}
FFMetaData *data = [self.ff metaDataForObj:book];
cell.titleLabel.text = book.title;
cell.priceLabel.text = [NSString stringWithFormat:@"$%@", book.price];
cell.authorLabel.text = book.author;
cell.descriptionLabel.text = book.description;
cell.dateLabel.text = [self.formatter stringFromDate:data.createdAt];
if(book.thumbnail == nil) {
cell.imageView.image = [UIImage imageNamed:@"messages.png"];
[self setCellImage:cell withBook:book atIndex:indexPath withTableView:tableView];
}
else {
cell.imageView.image = [UIImage imageWithData:book.thumbnail];
}
return cell;
}
この問題が発生する前は、tableView にセクションが 1 つしかなく、すべてが完全に機能していました。複数のセクションと行があるため、説明したように検索が壊れています。何か案は?また、[tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
以前は持っていましたが[self.tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
、今はそれを使用すると、検索しようとすると奇妙な例外が発生します。
NSInternalInconsistencyException'、理由: '無効なインデックス パスでの rect の要求 (2 つのインデックス [1, 1])'
だから私も混乱しています。助けてくれてありがとう!