使用搜索栏时 UIScrollview 冻结
我有一个控制器,顶部有一个搜索栏,当用户键入时,自动完成的搜索结果显示在其下方的 UIScrollView 中。
问题: 结果显示,但用户无法滚动这些结果。滚动视图被冻结。滚动的唯一方法是按搜索栏中的“取消”。点击“搜索”会隐藏键盘,但即使如此,滚动视图也会被冻结。
期望: 当用户输入时,搜索结果会自动完成。在任何给定时间,用户都可以滚动这些结果。他们不应该必须点击“取消”才能滚动。
结果的数量超出了屏幕所能容纳的范围,因此这不是内容仅比屏幕稍大的问题。
CancelButtonClicked 或 SearchButtonClicked 没有什么特别的:
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
searchBar.text = @"";
}
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
[searchBar resignFirstResponder];
[NSThread detachNewThreadSelector:@selector(fetchSearchResult:) toTarget:self withObject:searchBar.text];
}
- (void)searchBar:(UISearchBar *)searchBar
textDidChange:(NSString *)searchText {
if([searchBar.text length] >=3){
[mySpinner startAnimating];
[NSThread detachNewThreadSelector:@selector(fetchSearchResult:) toTarget:self withObject:searchBar.text];
}
}
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar {
self.searchDisplayController.searchResultsTableView.hidden = YES;
// This occurs when user starts entering text
// We want to keep the background area dark
}
I have a Controller with a search bar at top, and when the user types, autocompleted search results are shown below it, in a UIScrollView.
Problem:
The results show up, but the user can't scroll those results. The scrollview is frozen. The only way to scroll is to push 'Cancel' in the Search bar. Tapping "Search" hides the keyboard, but even then the scrollview is frozen.
Desired:
As the user is typing, search results are being autocompleted. At any given time, the user can scroll through those results. They should not have to hit Cancel in order to scroll.
There are more results than will fit on the screen so this isn't an issue of content being only slightly larger than the screen.
Nothing special in CancelButtonClicked or SearchButtonClicked:
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
searchBar.text = @"";
}
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
[searchBar resignFirstResponder];
[NSThread detachNewThreadSelector:@selector(fetchSearchResult:) toTarget:self withObject:searchBar.text];
}
- (void)searchBar:(UISearchBar *)searchBar
textDidChange:(NSString *)searchText {
if([searchBar.text length] >=3){
[mySpinner startAnimating];
[NSThread detachNewThreadSelector:@selector(fetchSearchResult:) toTarget:self withObject:searchBar.text];
}
}
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar {
self.searchDisplayController.searchResultsTableView.hidden = YES;
// This occurs when user starts entering text
// We want to keep the background area dark
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我可能有同样的问题: UISearchBar 嵌套在 UIScrollView 中,因此当显示搜索结果时 - 无法滚动父视图。
..我很困惑,但我学会了(UISearchDisplayCtrl private api< /a>) UISearchDisplayController 锁定所有父滚动视图(婊子)。
所以你应该添加类别 UISearchDisplayController+Custom:
I had possibly the same issue: UISearchBar was nested into UIScrollView, so when search results was shown- It was impossible to scroll parent view.
..I was puzzled but I learned (UISearchDisplayCtrl private api) that UISearchDisplayController locks all parent scroll views (bitch).
So U should add category UISearchDisplayController+Custom: