2

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;
}
Linjiong Cai
  • 83
  • 1
  • 1
  • 5
  • Could you try removing if (cell == nil) { cell = [[MovieCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } ? – EDUsta Aug 05 '14 at 15:18
  • Yeah, I tried. But it shows an error: "Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:" – Linjiong Cai Aug 05 '14 at 15:19
  • Is "return cell" gone missing or something? Since you're returning a cell. – EDUsta Aug 05 '14 at 15:21
  • I put this "return cell" at the end of the method. – Linjiong Cai Aug 05 '14 at 15:23
  • Try adding `[self.searchDisplayController.searchResultsTableView reloadData];` after creating/filtering the `filteredMovieArray` array. – Adam Aug 05 '14 at 16:09
  • It still doesn't work. :( – Linjiong Cai Aug 05 '14 at 16:21

1 Answers1

0

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

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.

Community
  • 1
  • 1
Linjiong Cai
  • 83
  • 1
  • 1
  • 5