使用搜索栏时 UIScrollview 冻结

发布于 2024-12-23 00:25:03 字数 1152 浏览 2 评论 0原文

我有一个控制器,顶部有一个搜索栏,当用户键入时,自动完成的搜索结果显示在其下方的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

站稳脚跟 2024-12-30 00:25:03

我可能有同样的问题: UISearchBar 嵌套在 UIScrollView 中,因此当显示搜索结果时 - 无法滚动父视图。
..我很困惑,但我学会了(UISearchDisplayCtrl private api< /a>) UISearchDisplayController 锁定所有父滚动视图(婊子)。

所以你应该添加类别 UISearchDisplayController+Custom:

@implementation UISearchDisplayController (Custom)

- (void)_disableParentScrollViews {
}

- (void)_enableParentScrollViews {
}

@end

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:

@implementation UISearchDisplayController (Custom)

- (void)_disableParentScrollViews {
}

- (void)_enableParentScrollViews {
}

@end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文