Search Bar in UITableView doesn't display text in Cell label

前端 未结 1 1139
轮回少年
轮回少年 2021-01-28 01:50

Here\'s where the magic isn\'t happening:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath    *)indexPath
{
static NSSt         


        
1条回答
  •  情深已故
    2021-01-28 02:53

    You need to have the searchResultsTableView dequeue a cell, not just your main table view. The cellForRowAtIndexPath method should look something like this:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        if (tableView == self.tableView) {
            RDTriangleCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
            cell.textLabel.text = self.theData[indexPath.row];
            return cell;
        }else{
            UITableViewCell *cell = [self.searchDisplayController.searchResultsTableView dequeueReusableCellWithIdentifier:@"SearchCell" forIndexPath:indexPath];
            //RDCell *cell = [self.searchDisplayController.searchResultsTableView dequeueReusableCellWithIdentifier:@"SearchCell" forIndexPath:indexPath];
            cell.textLabel.text = self.filteredData[indexPath.row];
            return cell;
        }
    }
    

    In viewDidLoad, you should register the class if you use the code I show above for a standard UITableViewCell.

    [self.searchDisplayController.searchResultsTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"SearchCell"];
    

    If you use a custom cell for the search results table, then you should use something like the line I have commented out, and register the nib for that custom cell.

    0 讨论(0)
提交回复
热议问题