Reputation: 1735
I have a cell prototype in storyboard. So I custom the height, subview (Labels and Images). But eventually the cell does not appear to be used for SearchDisplayController... Code snippet >>
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
#warning Reusable cell not working for custom cell.
ItemCell *cell = [tableView dequeueReusableCellWithIdentifier:itemCell];
if (cell == nil) {
cell = [[ItemCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:itemCell];
}
if (tableView == self.searchDisplayController.searchResultsTableView){
cell.itemLabel.text = [_filteredList objectAtIndex:indexPath.row];
cell.priceLabel.text = @"RM 7.00";
// TODO : Insert Image Here
} else {
cell.itemLabel.text = [_items objectAtIndex:indexPath.row];
cell.priceLabel.text = @"RM 7.00";
// TODO : Insert Image Here
}
return cell;}
I'm out of idea. Even if I use self.tableView instead of tableView it shows something like this.
Upvotes: 0
Views: 335
Reputation: 6529
add the following code before cell for row method.
- (void)searchDisplayController:(UISearchDisplayController *)controller didLoadSearchResultsTableView:(UITableView *)tableView
{
tableView.rowHeight = 24.0f; // this should be the same hight as the re usable cell you implemented
}
Then when the table view loads and search is performed the cell hight of the searchcontroller and the tableview would be the same.
Upvotes: 1
Reputation: 6079
you should make further changes using this method, for example:
-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
[controller.searchResultsTableView setBackgroundColor:[UIColor colorWithRed:0xED/255.0 green:0xED/255.0 blue:0xED/255.0 alpha:1.0]];
controller.searchResultsTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
return YES;
}
Upvotes: 0