public async void UpdateSearchResultsForSearchController(UISearchController searchController) { var searchString = searchController.SearchBar?.Text; try { ResultStrings = new List <NSAttributedString> (); if (!string.IsNullOrWhiteSpace(searchString)) { LocationResults = await WuAcClient.GetAsync(searchString, true); foreach (var result in LocationResults) { ResultStrings.Add(result.name.GetSearchResultAttributedString(searchString)); } } else { LocationResults = new List <WuAcLocation> (); } if (LocationResults.Any()) { emptyView.RemoveFromSuperview(); } else if (!emptyView.IsDescendantOfView(ParentViewController.View)) { initEmptyView(); } TableView?.ReloadData(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } }
async Task SearchWithStringAsync(ICharSequence constraint) { //var searchString = searchController.SearchBar?.Text; var searchString = constraint?.ToString(); if (searchString == null) { LocationResults = new List <WuAcLocation> (); ResultStrings = new List <SpannableString> (); //context.RunOnUiThread (adapter.NotifyDataSetInvalidated); return; } bool canceled = false; try { ResultStrings = new List <SpannableString> (); if (!string.IsNullOrWhiteSpace(searchString)) { LocationResults = await WuAcClient.GetAsync(searchString, true); Java.Lang.Object [] matchObjects = new Java.Lang.Object [LocationResults.Count]; for (int i = 0; i < LocationResults.Count; i++) { var name = LocationResults [i].name; ResultStrings.Add(name.GetSearchResultSpannableString(searchString)); matchObjects [i] = new Java.Lang.String(name); } filterResults.Values = matchObjects; filterResults.Count = LocationResults.Count; } else { LocationResults = new List <WuAcLocation> (); } } catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); canceled = true; } finally { if (!canceled) { publish = true; Activity.RunOnUiThread(() => PublishResults(constraint, filterResults)); } } }