UISearchDisplayContoller – can't prevent table reload on typing in search bar
2012-06-29 18:00
501 查看
http://stackoverflow.com/questions/3903718/uisearchdisplaycontoller-cant-prevent-table-reload-on-typing-in-search-bar/5342989#5342989
This is just the way UISearchDisplayController (SDC) works. When the user enters the first character into the searchBar the searchTable is loaded and displayed for the first time causing it to load. The methods "...shouldReloadTableForSearchString" and "...shouldReloadTableForSearchScope"
allow you to control whether the searchTable reloads automatically on subsequent chars or a scope change.
I've done both of the following to provide a good user experience on the first character. Slight disclaimer: I do have implementations of both of these that work but this is simply a framework for implementation from my memory. I may have missed a detail
but this should get you pretty close.
Option 1: Present a "loading" cell in the searchTable when the first char is typed.
This option allows the SDC to display the searchResultsTableView when the user types the first char, display status as to the current search/filter operation
in the SDC delegate class definition
add the iVar
add the iVar
in
set
in
set
call your method to load data in the background
return NO
when your background filter is complete:
set
in the various tableView delegate methods respond how you like to show status if there are current search results or results are loading in the background. What I did is:
if there are current search results, show results (even if loading/filtering in the background)
if there are no search results and
if there are no search results and
Option 2: Hide the searchTableView and display an overlay view in it's place until search results are loaded
This option hides the searchTableView when it is first loaded and only redisplays it if when the search/filter is complete. I defined this as an add on to option 1 as they can be done together though to optimize things you may not care about showing search
activity in the searchResultsTableView if you are hiding the table and showing the overlay.
in the SDC delegate class definition
same as Option 1
add the iVar
in
same as Option 1
create a UIView to use as an overlay in place of searchTableView containing whatever UI is appropriate for your app and set it to
in
release
in 'searchDisplayController:didShowSearchResultsTableView
if there are search results to display or
else (if
add
when your background filter is complete
same as option 1
if there are searchResults to display
else
in the various tableView delegate methods respond how you like to show status if there are current search results or results are loading in the background. What I did is:
same as option 1
This is just the way UISearchDisplayController (SDC) works. When the user enters the first character into the searchBar the searchTable is loaded and displayed for the first time causing it to load. The methods "...shouldReloadTableForSearchString" and "...shouldReloadTableForSearchScope"
allow you to control whether the searchTable reloads automatically on subsequent chars or a scope change.
I've done both of the following to provide a good user experience on the first character. Slight disclaimer: I do have implementations of both of these that work but this is simply a framework for implementation from my memory. I may have missed a detail
but this should get you pretty close.
Option 1: Present a "loading" cell in the searchTable when the first char is typed.
This option allows the SDC to display the searchResultsTableView when the user types the first char, display status as to the current search/filter operation
in the SDC delegate class definition
add the iVar
BOOL isLoading
add the iVar
UITableView *searchTableView
in
searchDisplayController:didLoadSearchResultsTableView
set
searchTableView = tableView
in
shouldReloadTableForSearchString/Scope
set
isLoading = YES
call your method to load data in the background
return NO
when your background filter is complete:
set
isLoading = NO
[searchTableView reloadData]
in the various tableView delegate methods respond how you like to show status if there are current search results or results are loading in the background. What I did is:
if there are current search results, show results (even if loading/filtering in the background)
if there are no search results and
isLoading == NOreturn 1 row and show 'No matches' in a cell
if there are no search results and
isLoading == YESreturn 1 row and and show search activity in a cell (I typically use UIActivityIndicatorView)
Option 2: Hide the searchTableView and display an overlay view in it's place until search results are loaded
This option hides the searchTableView when it is first loaded and only redisplays it if when the search/filter is complete. I defined this as an add on to option 1 as they can be done together though to optimize things you may not care about showing search
activity in the searchResultsTableView if you are hiding the table and showing the overlay.
in the SDC delegate class definition
same as Option 1
add the iVar
UIView *searchTableOverlayView
in
searchDisplayController:didLoadSearchResultsTableView
same as Option 1
create a UIView to use as an overlay in place of searchTableView containing whatever UI is appropriate for your app and set it to
searchTableOverlayView
in
searchDisplayController:didUnloadSearchResultsTableView
release
searchTableOverlayView
in 'searchDisplayController:didShowSearchResultsTableView
(may be able to do this insearchDisplayController:willShowSearchResultsTableView`
if there are search results to display or
isLoading == NO
seachTableOverlayView.hidden == YES
else (if
isLoading == YES)
searchTableOverlayView.frame == searchResultsTableView.frame
add
seachTableOverlayViewas a subview of
searchTableVIew.superview
searchTableView.hidden = YES
when your background filter is complete
same as option 1
if there are searchResults to display
searchTableCoverView.hidden = YES'</li> <li>searchResultsTableView.hidden = NO'
else
searchResultsTableView.hidden = YES
searchTableCoverView.hidden = NO
in the various tableView delegate methods respond how you like to show status if there are current search results or results are loading in the background. What I did is:
same as option 1
相关文章推荐
- How do I cover the “no results” text in UISearchDisplayController's searchResultTableView?
- iOS - 搜索框UISearchController的使用(iOS8.0之后替代UISearchBar + UISearchDisplayController的组合)
- iOS--UISearchBar和UISearchDisplayController
- UISearchBar 和 UISearchDisplayController 没有在UITableView 的headerView 导致searchResultsTableView的frame出问题
- iOS --- 搜索框UISearchController的使用(iOS8.0以后替代UISearchBar + UISearchDisplayController的组合)
- UI_搜索框UISearchController的使用(iOS8.0以后替代UISearchBar + UISearchDisplayController)
- IOS--常用控件--UISearchBar和UISearchDisplayController
- 搜索框UISearchController的使用(iOS8.0以后替代UISearchBar + UISearchDisplayController)
- uisearchDisplayController放在tableview里下拉刷新状态出现遮挡
- IOS-模糊搜索UISearchBar+UISearchDisplayController
- UISearchBar和UISearchDisplayController
- 【IOS 开发学习总结-OC-53】★★ios开发UI 控件——UISearchBar与UISearchDisplayController
- UISearchBar和UISearchDisplayController
- UISearchBar和UISearchDisplayController
- iPhone Tutorial: Adding a search bar in TableView
- UISearchController VS UISearchBar and UISearchDisplayController
- 修复UISearchDisplayControllerd的searchResultsTableView的contentSize不正确
- 关于UISearchDisplayController和 uisearchBar使用时遇到的问题
- UISearchBar和UISearchDisplayController
- UISearchBar 和 UISearchDisplayController的使用