为此,您需要更改 MonoTouch.Dialog.DialogViewController 并使void SetupSearch()
受保护的虚拟。
然后,在您的控制器中使用以下代码覆盖 SetupSearch 方法。这种方法的缺点是您必须使用自定义搜索委托。但是,从您对其他一些问题的回答来看,您似乎已经在这样做了。
protected override void SetupSearch()
{
SearchBar = new UISearchBar(new RectangleF (0, 0, TableView.Bounds.Width, 90))
{
Delegate = new MySearchBarDelegate(this),
Placeholder = "Search".t(),
ShowsScopeBar = true,
ScopeButtonTitles = new [] { "Girl".t(),"Boy".t(),"All".t() },
SelectedScopeButtonIndex = 0,
};
TableView.TableHeaderView = SearchBar;
}
public class MySearchBarDelegate : UISearchBarDelegate
{
MyViewController _container;
public SearchDelegate (MyViewController container)
{
_container = container;
}
public override void SelectedScopeButtonIndexChanged (UISearchBar searchBar, int index)
{
_container.SearchScopeChanged(searchBar, index);
}
public override void OnEditingStarted (UISearchBar searchBar)
{
searchBar.ShowsCancelButton = true;
_container.StartSearch ();
}
public override void OnEditingStopped (UISearchBar searchBar)
{
searchBar.ShowsCancelButton = false;
_container.FinishSearch ();
}
public override void TextChanged (UISearchBar searchBar, string searchText)
{
_container.PerformFilter (searchText ?? "");
}
public override void CancelButtonClicked (UISearchBar searchBar)
{
searchBar.ShowsCancelButton = false;
_container.SearchBar.Text = "";
_container.FinishSearch ();
searchBar.ResignFirstResponder ();
}
public override void SearchButtonClicked (UISearchBar searchBar)
{
_container.SearchButtonClicked (searchBar.Text);
}
}