Created
April 22, 2019 16:36
-
-
Save felipeslongo/af76815b6264a992f99ea50106a6673a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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