我有一个由CoreData DB填充的iOS 7 UITableView;它工作得很好。我添加了一个搜索数据库的UISearchDisplayController;除了搜索只显示一些结果(小于屏幕上可以容纳的数量)的小情况之外,这种情况很有效。在这种情况下,我最终看到额外的空白单元格不会滚动到我的结果下方。这是一个例子:
非滚动线之间的分隔线的宽度似乎是由我的表视图的storybord选项中的'Separator Insets'的自定义宽度控制的,所以我知道它们来自哪里,我只是不喜欢不知道怎么阻止他们出现。在我的故事板中,表格视图的内容设置为“动态原型”,只有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
}
我避免在此处粘贴整个文件以缩短问题但如果您需要其他代码段(或任何其他信息),请告诉我们。感谢。
答案 0 :(得分:1)
试试这个,
故事板 - >表视图 - >属性检查器 - >风格 - >分组