UISearchDisplayController not correctly displaying custom cells

后端 未结 6 1545
抹茶落季
抹茶落季 2020-12-29 11:58

So I have a tableView that has sections and rows, and it uses a custom cell class. The custom cell has an image view and a few labels. The table view works fine, and the sea

6条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-29 12:47

    My summary for UITableView with Search Bar and Search Display using same custom cell designed in storyboard protype:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *CellIdentifier = @"CellIdentifierAsYouDefinedInStoryboard";
    
        CustomTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
        if (cell == nil) {
            cell = [[CustomTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        }
    
        if (tableView == self.searchDisplayController.searchResultsTableView) {
            /* searchResultsTableView code here */
        } else {
            /* Base tableView table code here */
        }
    
        /* more cell code here */
    
        return cell;
    }
    


    and then add this line for searchResultsTableView to match your custom cell height:

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        [self.searchDisplayController.searchResultsTableView setRowHeight:self.tableView.rowHeight];
    
         /* more of your viewDidLoad code */
    }
    

提交回复
热议问题