1

使用 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 secMain = new Section("Top 100".t());

在此处输入图像描述

4

1 回答 1

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);
        }
    }
于 2013-03-26T23:46:39.123 回答