首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用“全选”和“取消全选”按钮获取UITableView

问如何使用“全选”和“取消全选”按钮获取UITableView
EN

Stack Overflow用户
提问于 2011-10-26 21:52:12
回答 2查看 797关注 0票数 1

我想要桌面查看附件按钮,如选择高或取消选择高。

cell.Accessory = UITableViewCellAccessory.None;我想要一个按钮的例子:“全选”当用户触摸这个按钮时,每个单元格的附件都应该勾选。或者我想要“重置”按钮。如果用户触摸此按钮,每个复选标记都会消失,Cell的附件也不会显示任何内容。

EN

回答 2

Stack Overflow用户

发布于 2011-10-31 08:16:00

正如您可能已经发现的那样,使用UITableView有点复杂。但是,有一个用于MonoTouch的奇妙的库,称为MonoTouch.Dialog,它使事情变得简单得多。

下面的示例代码使用MonoTouch.Dialog回答您的问题(据我所知,如果我的答案不符合您的要求,请让我知道)。

代码语言:javascript
复制
    UIBarButtonItem [] selection_buttons;

    void Process (IList<Element> list, bool value)
    {
        foreach (Element e in list) {
            CheckboxElement cb = e as CheckboxElement;
            if (cb == null)
                continue;
            cb.Value = value;
            cb.GetImmediateRootElement ().Reload (cb, UITableViewRowAnimation.None);
        }
    }

    void Test ()
    {
        Section s = new Section ("Select items");
        for (int i = 0; i < 10; i++)
            s.Add (new CheckboxElement (i.ToString ()));
        var root = new RootElement (String.Empty);
        root.Add (s);

        var dv = new DialogViewController (root, true);

        // keep buttons in a field, not a local variable, to ensure it won't be GC'ed away
        if (selection_buttons == null) {
            selection_buttons = new UIBarButtonItem [] { 
                new UIBarButtonItem ("Deselect All", UIBarButtonItemStyle.Plain, delegate {
                    Process (s.Elements, false);
                }),
                new UIBarButtonItem ("Select All", UIBarButtonItemStyle.Plain, delegate {
                    Process (s.Elements, true);
                })
            };
        }

        dv.NavigationItem.SetRightBarButtonItems (selection_buttons, true);
        NavigationController.PushViewController (dv, true);             
    }

祝你和MonoTouch (和MonoTouch.Dialog)玩得开心!

票数 5
EN

Stack Overflow用户

发布于 2012-11-09 17:13:09

您可以从developer.apple.com中检出this demo。希望能对你有所帮助。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7903604

复制
相关文章

相似问题

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