【发布时间】:2014-01-20 01:33:00
【问题描述】:
我有一个由 CoreData DB 填充的 iOS 7 UITableView;它工作得很好。我添加了一个搜索数据库的 UISearchDisplayController;这很好用,除了搜索只会显示几个结果(少于屏幕上可以容纳的数字)的小情况。在这种情况下,我最终会看到额外的空白单元格不会滚动到我的结果下方。这是一个例子:
非滚动线之间分隔线的宽度似乎由我的表格视图的故事板选项中“分隔符插入”的自定义宽度控制,所以我知道它们来自哪里,我只是不不知道如何阻止他们出现。在我的故事板中,表格视图的内容设置为“动态原型”,只有 1 个原型单元。我还在情节提要中的表格视图中附加了带有范围的搜索栏。
这是我用来管理搜索交互的一些代码。
#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
}
我避免在此处粘贴整个文件以缩短问题,但如果您需要其他代码 sn-ps(或任何其他信息),请告诉我。谢谢。
【问题讨论】:
-
嗯,大约 2 周后没有回复。请让我知道我是否可以提供更多信息等以帮助追查此问题。
标签: ios uitableview ios7 uisearchdisplaycontroller