现在我有一个动态单元格来显示列表。并使用搜索栏和搜索显示 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/