首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Monotouch.Dialog:被SectionHeader隐藏的ScopeBar

Monotouch.Dialog:被SectionHeader隐藏的ScopeBar
EN

Stack Overflow用户
提问于 2013-01-28 02:26:56
回答 1查看 348关注 0票数 1

我使用MonoTouch.Dialog添加了一个简单的表并添加了一个ScopeBar:

代码语言:javascript
复制
     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出现在范围栏的顶部:

代码语言:javascript
复制
Section secMain = new Section("Top 100".t());

EN

回答 1

Stack Overflow用户

发布于 2013-03-27 07:46:39

为此,您需要更改MonoTouch.Dialog.DialogViewController并使void SetupSearch()受保护成为虚拟的。

然后,在控制器中用下面的代码覆盖SetupSearch方法。这种方法的缺点是您必须使用自定义的搜索委托。但从你对其他一些问题的回答来看,你似乎已经在这么做了。

代码语言:javascript
复制
    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);
        }
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14550653

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档