Can't make table view inactive when search bar is in use. iPhone

折月煮酒 提交于 2019-12-24 09:15:16

问题


I have a table view with a search bar above it, and when the search bar is pressed I want the table view to become inactive. So I have this method:

- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
{
    self.tableView.userInteractionEnabled = NO;
}

with the same class being the UISearchBarDelegate. For some reason though it doesn't disable the table view. Any thoughts? Let me know if there's any other pieces of code needed to help. Thanks.


回答1:


Not sure why userInteractionEnabled is not making your UITableView inactive, but I can suggest an alternative approach.

I recently moved a project over from manually adding a UISearchBar as a subview of my UITableView to using a UISearchDisplayController. I can definitely recommend doing it this way. The SearchDisplayController will animate in a alpha blended view behind the search bar which prevents interaction with the underlying table view, which would avoid the problem you are having.

Update:

This might be something to do with the way you are adding your UISearchDisplayController. Does your view hierarchy look like this?



来源:https://stackoverflow.com/questions/3294701/cant-make-table-view-inactive-when-search-bar-is-in-use-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!