ios - 取消按钮单击/ tableview reloadData 功能后,搜索栏从 tableview 标题中消失
问题描述
我在使用 Objective-C 的应用程序中使用 searchController 更改了 searchDisplayController 以支持 ios 8。
它在第一次尝试时效果很好,但是每当我单击搜索栏上的取消按钮时,动画完成后,我的搜索栏就会消失。我不希望它消失,每当我返回主屏幕并返回搜索栏屏幕时,它就会完美显示。
我已经尝试将搜索栏放在情节提要的表格视图之外,但不起作用。我还尝试了几乎所有我能找到的网络解决方案。
编辑:我在另一个 .m 文件中尝试了相同的代码块,它在该屏幕中运行良好,在我假设的取消按钮后,某些东西会覆盖-重新加载 tableview,但我找不到它是什么。会是什么?我错过了什么?
EDIT.2:tableview reloadData 功能使其消失,仍然没有解决方案。
这是关于搜索栏的代码
- (void)viewDidLoad {
[super viewDidLoad];
self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
self.searchController.searchResultsUpdater = self;
self.searchController.dimsBackgroundDuringPresentation = NO;
self.searchController.searchBar.delegate = self;
self.tableView.tableHeaderView = self.searchController.searchBar;
self.definesPresentationContext = YES;
[self.searchController.searchBar sizeToFit];
}
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self.searchController.searchBar setTranslucent:NO];
[self.searchController.searchBar setBackgroundColor:_themeColor];
}
- (void)updateSearchResultsForSearchController:(UISearchController *)searchController
{
NSString *searchString = searchController.searchBar.text;
[self searchForText:searchString];
[self.tableView reloadData];
}
- (void)searchBar:(UISearchBar *)searchBar selectedScopeButtonIndexDidChange:(NSInteger)selectedScope
{
[self updateSearchResultsForSearchController:self.searchController];
}
- (void)searchForText:(NSString *)searchString
{
[self filterContentForSearchText:searchString
scope:[[self.searchController.searchBar scopeButtonTitles]
objectAtIndex:[self.searchController.searchBar
selectedScopeButtonIndex]]];
}
解决方案
推荐阅读
- podman - 无法使用 allow_host_loopback=true 解析 DNS
- assembly - 在 x86 程序集中存储大量布尔值的最佳方法是什么?
- ios - RotationGestureHandler react-native-gesture-handler:如何只用一根手指激活旋转手势?
- node.js - 没有为 null 类型定义协议方法 IDeref.-deref
- reactjs - docker 程序未检测到卷更改
- flutter - Flutter OnTap Listview 项
- javascript - Javascript innerHTML 被自动覆盖并失效
- jenkins-pipeline - 在 Jenkins-Openshift 容器中执行 Cypress 测试
- html - 尝试在 CSS 中的下拉选择中更改悬停时的选项背景颜色
- ios - iPad 在多任务处理 Slide Over (SwiftUI/UIKit) 中的键盘安全区域错误