问题描述
限时送ChatGPT账号..我有一个包含所有国家及其国旗的表格视图.我一直在努力添加一个搜索栏并让它一切正常,直到我决定将搜索栏移动到 iOS7 允许的导航栏中(就我而言,该布局效果很好).
I have a tableview containing all the countries and their flags. I've been working to add a search bar and had it all working until I decided to move the search bar into the navigation bar allowed in iOS7 (for my purposes, that layout works very well).
现在,表格加载正常,搜索栏显示正常.当我在搜索栏中输入时,我可以看到通过控制台构建的过滤列表.一切看起来都不错,除了搜索结果表从不显示.换句话说,我在新的 tableview 中看不到过滤列表.
Now, the table loads fine, the search bar shows up fine. As I type into the search bar, I can see the filtered list being built via the console. All looks good, EXCEPT the search results table never displays. In other words, I don't see the filtered list in a new tableview.
正在调用此方法来构建过滤列表:
This method is being called to build the filtered list:
-(void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
但是标准方法:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
永远不会被调用.
正如我所说,当搜索栏不在导航栏中时,它工作正常.我在 ViewDidLoad 中分配了以下委托和属性:
As I said, it's working fine when the search bar isn't in the navigation bar. I have assigned the following delegates and properties in ViewDidLoad:
searchDisplayController.delegate = self;
searchDisplayController.searchResultsDataSource = self;
searchDisplayController.searchResultsDelegate = self;
searchDisplayController.displaysSearchBarInNavigationBar = YES;
我也有:
#pragma mark - UISearchDisplayController Delegate Methods
-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString {
// Tells the table data source to reload when text changes
[self filterContentForSearchText:searchString scope:
[[searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:[searchDisplayController.searchBar selectedScopeButtonIndex]]];
// Return YES to cause the search result table view to be reloaded.
return YES;
}
我错过了什么???
推荐答案
我遇到了与 Morpheus 相同的问题,这是由于 self.edgesForExtendedLayout = UIRectEdgeNone;
在我的 viewDidLoad
I was having the same issue as Morpheus, and it was due to having self.edgesForExtendedLayout = UIRectEdgeNone;
in my viewDidLoad
这篇关于iOS7导航栏中的SearchBar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论