在tableview中搜索过滤后,为什么显示空白单元格?

时间:2022-09-15 22:21:51

Now I have a dynamic cell to show lists. And Using Search Bar and Search Display Controller. Why it shows blank on simulator.

现在我有一个动态单元格来显示列表。并使用搜索栏和搜索显示控制器。为什么它在模拟器上显示为空白。

Before filtering,the simulator shows all cells and disclosure could link to another table view. After filtering, it should show some of cells. But it is blank. And the disclosure is not worked as well.

在过滤之前,模拟器显示所有单元格,并且公开可以链接到另一个表格视图。过滤后,它应显示一些单元格。但它是空白的。并且该披露没有得到妥善处理。

Codes for cell:

细胞代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"MovieCell";
MovieCell *cell = (MovieCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
Movie *movie = nil;

if (cell == nil) {
    cell = [[MovieCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
if (tableView == self.searchDisplayController.searchResultsTableView) {
    movie= [filteredMovieArray objectAtIndex:[indexPath row]];
} else {
    movieArray = self.movies;
    movie = [movieArray objectAtIndex:[indexPath row]];
}

cell.nameLabel.text = movie.movieName;

cell.placeLabel.text = movie.place;
cell.categoryLabel.text = movie.category;
cell.isFavLabel.text = movie.isFavourite ? @"Favourite" : @"Not Favourite";

[cell.starRating setRating:movie.rating];

[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
 NSLog(@"description = %@",[cell description]);
return cell;
}

1 个解决方案

#1


0  

I made it. I think this is a good answer for it: Search Bar in UITableView doesn't display text in Cell label.

我做到了。我认为这是一个很好的答案:UITableView中的搜索栏不会在Cell标签中显示文本。

What's more, I also add this code section to fit the cell height:

更重要的是,我还添加了此代码部分以适应单元格高度:

- (void)searchDisplayController:(UISearchDisplayController *)controller didLoadSearchResultsTableView:(UITableView *)tableView {
tableView.rowHeight = 87;
}

This number is the row height of my cell.

这个数字是我单元格的行高。

#1


0  

I made it. I think this is a good answer for it: Search Bar in UITableView doesn't display text in Cell label.

我做到了。我认为这是一个很好的答案:UITableView中的搜索栏不会在Cell标签中显示文本。

What's more, I also add this code section to fit the cell height:

更重要的是,我还添加了此代码部分以适应单元格高度:

- (void)searchDisplayController:(UISearchDisplayController *)controller didLoadSearchResultsTableView:(UITableView *)tableView {
tableView.rowHeight = 87;
}

This number is the row height of my cell.

这个数字是我单元格的行高。