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

标签 ios objective-c uitableview

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

在过滤之前,模拟器会显示所有单元格,并且披露可以链接到另一个表格 View 。过滤后,它应该显示一些单元格。但它是空白的。而且披露也没有奏效。

单元格代码:

- (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;
}

最佳答案

我做到了。我认为这是一个很好的答案:Search Bar in UITableView doesn't display text in Cell label .

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

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

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

关于ios - 在tableview中搜索过滤后,为什么它显示空白单元格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25142424/

相关文章:

ios - MapBox 导航舱无法在我使用 Xcode 9.2 的地方使用 ObjectiveC 安装

ios - UICollectionView 自动调整高度

ios - UITableView 在重新加载时闪烁

ios - 在 UITableViewCell 中有条件地移动和删除布局对象

ios - CreateNewUser() firebase 方法在用户 uid 的闭包中返回 nil

objective-c - 我如何获得 MPAVController "setting movie path"

objective-c - 有没有办法在 xcode 中轻松运行一组特定的测试或单个测试?

iphone - 使用固定中心点为 UIButton 中的宽度变化设置动画

objective-c - iOS - 在变量中存储对对象的引用

ios - 如何在不使用原型(prototype)单元的情况下创建表格 View 单元?