来自UISearchDisplayController的结果后可见的额外单元格 [英] Extra cells visible after results from UISearchDisplayController

查看:80
本文介绍了来自UISearchDisplayController的结果后可见的额外单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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:

非滚动线之间的分隔线的宽度似乎是由我的表视图的storybord选项中的'Separator Insets'的自定义宽度控制的,所以我知道这是他们来自哪里,我只是不知道如何阻止他们出现。在我的故事板中,表格视图的内容设置为动态原型,只有1个原型单元格。我还将带有范围的搜索栏附加到故事板中的表格视图。

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.

推荐答案

试试这个,

故事板 - >表查看 - >属性检查器 - >样式 - >分组

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

这篇关于来自UISearchDisplayController的结果后可见的额外单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆