Extra cells visible after results from UISearchDisplayController

╄→尐↘猪︶ㄣ 提交于 2019-12-10 11:48:23

问题


I have a iOS 7 UITableView populated by a CoreData DB; it's working great. I added a UISearchDisplayController that searches the database; this works well except for the small case where a search would only display a few results (less than the number that can fit on the screen). In that case, I end up seeing extra blank cells that don't scroll below my results. Here's an example:

The width of the divider between the non-scrolling lines seems to be controlled by the custom width of the 'Separator Insets' in the storybord options for my Table View, so I know that's where they're from, I just don't know how to stop them from showing up. In my storyboard the Content of the Table View is set to 'Dynamic Prototypes' with just 1 prototype cell. I've also attached the search bar with scope to my table view in the storyboard.

Here's some of the code I use to manage the search interaction.

#pragma mark - Search
// This gets called when you start typing text into the search bar
-(BOOL)searchDisplayController:(UISearchDisplayController *)_controller shouldReloadTableForSearchString:(NSString *)searchString {
    self.searchString = searchString;
    self.fetchedResultsController = nil;

    [self setFetchedResultsControllerWithContext:self.managedObjectContext andPredicate:[self searchPredicateGenerator]];

    return YES;
}

// This gets called when you change the search bar scope
-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchScope:(NSInteger)searchOption {
    self.searchBar.selectedScopeButtonIndex = searchOption;
    self.fetchedResultsController = nil;

    [self setSearchBarPlaceholdersForCase:searchOption];

    [self setFetchedResultsControllerWithContext:self.managedObjectContext andPredicate:[self searchPredicateGenerator]];

    return YES;
}

// To generate search predicates
-(NSPredicate *)searchPredicateGenerator {
    return [NSPredicate predicateWithFormat:[NSString stringWithFormat: @"%@ AND ((title CONTAINS[cd] \"%@\") OR (descriptionText CONTAINS[cd] \"%@\"))",
                                             [self stringPredicateForCase:self.searchBar.selectedScopeButtonIndex],
                                             self.searchString,
                                             self.searchString ]];
}

// This gets called when you cancel or close the search bar
- (void)searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller{
    self.searchString = nil;
    self.fetchedResultsController = nil;

    [self setFetchedResultsControllerWithContext:self.managedObjectContext andPredicate:self.filterPredicate];
}

// to tell the search controller which cells to use here
- (void)searchDisplayController:(UISearchDisplayController *)controller didLoadSearchResultsTableView:(UITableView *)tableView {
    [tableView registerClass:[TWLTableCell class]  forCellReuseIdentifier:@"MarkIdentifier"];
    tableView.rowHeight = TWLTABLE_ROW_HEIGHT; // or some other height
}

I've avoided pasting whole files here to keep the question shorter but if you need other code snippets (or any other info) please let me know. Thanks.


回答1:


Try this,

Story Board -> Table View -> Attributes Inspector -> Style -> Grouped



来源:https://stackoverflow.com/questions/21224937/extra-cells-visible-after-results-from-uisearchdisplaycontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!