Skip to content

Instantly share code, notes, and snippets.

@felipeslongo
Created April 22, 2019 16:36
Show Gist options
  • Save felipeslongo/af76815b6264a992f99ea50106a6673a to your computer and use it in GitHub Desktop.
Save felipeslongo/af76815b6264a992f99ea50106a6673a to your computer and use it in GitHub Desktop.
using System;
using UIKit;
namespace App.iOS.Extensions
{
public static class UIViewController_AddSearchController
{
public static UISearchController AddSearchController(this UIViewController @this)
{
var searchController = new UISearchController(null as UIViewController);
searchController.SearchResultsUpdater = @this as IUISearchResultsUpdating ??
throw new IUISearchResultsUpdatingNotImplementedException(@this);
searchController.ObscuresBackgroundDuringPresentation = false;
searchController.SearchBar.Placeholder = "Buscar";
@this.NavigationItem.SearchController = searchController;
@this.NavigationItem.HidesSearchBarWhenScrolling = false;
@this.DefinesPresentationContext = true;
return searchController;
}
private class IUISearchResultsUpdatingNotImplementedException : Exception
{
public ControllerNaoImplementaBarraDeBuscaException(UIViewController controller) :
base ($"Controller {controller.GetType().Name} deve implementar interface {typeof(IUISearchResultsUpdating).Name}")
{}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment