UISearchView not displaying search values

前端 未结 1 1720
小鲜肉
小鲜肉 2020-12-07 00:04

In my TableView which Expands on the clicking on the sections.now I am using Uisearchbar to search the sections in the table...It gives me the

相关标签:
1条回答
  • 2020-12-07 01:00

    You are not reloading your table after searching

    - (void)filterContentForSearchText:(NSString*)searchText
                                 scope:(NSString*)scope
    {
        NSPredicate *resultPredicate = [NSPredicate
                                        predicateWithFormat:@"SELF contains[cd] %@",
                                        searchText];
    
    self.mySections = [self.mySections filteredArrayUsingPredicate:resultPredicate];
    [myTableView reloadData];
    }  
    

    Edit

    Your are not setting detail text label

    if ([tableView isEqual:self.searchDisplayController.searchResultsTableView]) 
    {
        cell.textLabel.text = [self.searchResults objectAtIndex:indexPath.row];
    cell.detailTextLabel.text=[dataForSection valueForKey:[self.searchResults objectAtIndex:indexPath.row]];
    }  
    

    and after searching you are getting title now row because in your code

     rows = [self.searchResults count];
    return rows;  
    

    its always returning zero value. So just do it return 1;

    And do other thing as your requirement,

    And i will suggest you to not to use different different code for before table search and after searching.. Like if ([tableView isEqual:self.searchDisplayController.searchResultsTableView])

    just use same code for both..and make changes only in array and dictionary..

    initially

    tableAry = globalAry;
    

    And after searching

    tableAry = searchedAry;
    
    0 讨论(0)
提交回复
热议问题