ios - UISearchDisplayController 结果后可见的额外单元格

标签 ios uitableview ios7 uisearchdisplaycontroller

我有一个由 CoreData 数据库填充的 iOS 7 UITableView;它工作得很好。我添加了一个搜索数据库的 UISearchDisplayController;这很好用,除了搜索只显示几个结果(少于屏幕上可以显示的数量)的小情况。在那种情况下,我最终会看到额外的空白单元格不会滚动到我的结果下方。这是一个例子:

UISearch Weirdness

非滚动线之间分隔线的宽度似乎由我的 TableView 的故事情节选项中“分隔符插入”的自定义宽度控制,所以我知道那是它们的来源,我只是不不知道如何阻止他们出现。在我的 Storyboard 中,表格 View 的内容设置为“动态原型(prototype)”,只有 1 个原型(prototype)单元格。我还将带有范围的搜索栏附加到 Storyboard 中的 TableView 。

这是我用来管理搜索交互的一些代码。

#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
}

我避免在此处粘贴整个文件以使问题更短,但如果您需要其他代码片段(或任何其他信息),请告诉我。谢谢。

最佳答案

试试这个,

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

关于ios - UISearchDisplayController 结果后可见的额外单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21224937/

相关文章:

ios - 有没有办法不分配 UIModalTransitionStyle?

ios - 实现垂直时间线的最佳方式是什么 - iOS

ios7 - iOS 7 NSURLSession 在后台下载多个文件

uitableview - iOS 7 : Dragging in UITableView/delaysContentTouches seems not working

ios - 显示和隐藏 UIPickerview 时出错

ios - 使 UIAlertViewController Action 不可点击?

android - 在平板设备上填充

ios - 如何合并两个 SwiftyJSON 对象

ios - Swift:如何将单元格 View 设计为两个三角形?

ios - 当数据来自网络时重用 UIViewController 的文件管理器