使用MonoTouch.Dialog我添加一个简单的表并添加一个ScopeBar:
this.Style = UITableViewStyle.Plain;
this.EnableSearch = true;
this.AutoHideSearch = false;
this.SearchPlaceholder = "Search".t();
UISearchBar sb = TableView.TableHeaderView as UISearchBar;
if (sb != null)
{
sb.ScopeButtonTitles = new string[] { "Girl".t(),"Boy".t(),"All".t() };
sb.ShowsScopeBar = true;
sb.SizeToFit();
}
看起来不错:
当我设置Section并给它一个标题时,该部分显示在范围栏的顶部:
Section secMain = new Section("Top 100".t());
答案 0 :(得分:0)
为此,您需要更改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);
}
}