SearchResultsUpdating not being called in UISearch

2019-08-17 19:18发布

问题:

I'm working with UISearchController in Xamarin.Ios and everything works fine but when I start typing, the SearchhResultUpdating method is not override is not firing. It works sometimes and doesn't somw other times but now it doesn't work at all.

Here's the SearchResultsUpdating Class:

class SearchResult : UISearchResultsUpdating
{
    public event Action<string> UpdateSearchResults = delegate { };

    public override void UpdateSearchResultsForSearchController(UISearchController searchController)
    {

        this.UpdateSearchResults(searchController.SearchBar.Text);
    }
}

and Here's when I used it:

 var searchresult = new SearchResult();
 searchresult.UpdateSearchResults += searchResultsController.Search;
 var searchController = new UISearchController(searchResultsController) { SearchResultsUpdater = searchresult };

回答1:

You should make searchController as global variable .

If you do that , it won't release and keep in its life circle , and fire that method in UISearchResultsUpdating

Refer to this Demo