我使用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出现在范围栏的顶部:
Section secMain = new Section("Top 100".t());

发布于 2013-03-27 07:46:39
为此,您需要更改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);
}
}https://stackoverflow.com/questions/14550653
复制相似问题