iOS7导航栏中的SearchBar

编程入门 行业动态 更新时间:2024-10-09 16:26:58
本文介绍了iOS7导航栏中的SearchBar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送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:关键词]

本文发布于:2023-04-29 01:44:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1182547.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:栏中   SearchBar

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!