未在 UISearchController 中调用 SearchResultsUpdating [英] SearchResultsUpdating not being called in UISearchController

查看:27
本文介绍了未在 UISearchController 中调用 SearchResultsUpdating的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Xamarin.Ios 中使用 UISearchController 并且一切正常,但是当我开始输入时,SearchhResultUpdating 方法未覆盖未触发.它有时工作,有时不工作,但现在它根本不起作用.

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.

这是 SearchResultsUpdating 类:

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);
    }
}

这是我使用它的时间:

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

推荐答案

你应该把 searchController 作为 全局变量 .

如果你这样做,它不会释放并保持在它的生命周期中,并在 UISearchResultsUpdating

参考这个Demo

这篇关于未在 UISearchController 中调用 SearchResultsUpdating的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆