Mono 如何使用“全选”和“全选”按钮获取UITableView

Mono 如何使用“全选”和“全选”按钮获取UITableView,mono,uikit,xamarin.ios,uitableview,Mono,Uikit,Xamarin.ios,Uitableview,我想查看附件按钮,如selectall或DecelectAll。 cell.accessority=UITableViewCellAccessority.None; 我想要一个按钮示例:全选 当用户触摸此按钮时,everycell的附件应打勾。 或者我要重置按钮。如果用户点击此按钮,每个复选标记都会消失,并且单元格的附件应该没有 您可能已经发现,使用UITableView有点复杂。然而,MonoTouch有一个很棒的库,名为,它使事情变得更容易 下面的示例代码使用MonoTouch.Dialog

我想查看附件按钮,如selectall或DecelectAll。 cell.accessority=UITableViewCellAccessority.None; 我想要一个按钮示例:全选 当用户触摸此按钮时,everycell的附件应打勾。
或者我要重置按钮。如果用户点击此按钮,每个复选标记都会消失,并且单元格的附件应该没有

您可能已经发现,使用UITableView有点复杂。然而,MonoTouch有一个很棒的库,名为,它使事情变得更容易

下面的示例代码使用MonoTouch.Dialog尽可能多地回答您的问题,如果我的答案不符合您的要求,请告诉我

    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的乐趣。对话

您可能已经发现,使用UITableView有点复杂。然而,MonoTouch有一个很棒的库,名为,它使事情变得更容易

下面的示例代码使用MonoTouch.Dialog尽可能多地回答您的问题,如果我的答案不符合您的要求,请告诉我

    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的乐趣。对话

您可以在developer.apple.com上结账。希望对你有帮助

您可以在developer.apple.com上结账。希望对你有帮助

你能更详细地描述一下吗?我不明白你的问题。对不起,我不明白你的问题。你能编辑它来提供更多细节吗?特别是按钮和UITableViewCell附件之间的链接。后者在这里被记录:你能更具描述性吗?我不明白你的问题。对不起,我不明白你的问题。你能编辑它来提供更多细节吗?特别是按钮和UITableViewCell附件之间的链接。后面的内容记录在这里:顺便问一下:SDK 5的新静态表是用Monotouch绑定的,还是您希望人们使用Monotouch.Dialog?@Krumelur应该在那里-缺少的任何东西都是一个bug。我们寻求提供选择,包括在可能的情况下提供所有iOS功能和更简单的API,并且比wrt UITableView更方便-顺便问一下:SDK 5的新静态表是用Monotouch绑定的还是你想让人们使用Monotouch.Dialog?@Krumelur应该在那里-缺少的东西都是bug。我们寻求提供选择,包括在可能的情况下提供所有iOS功能和更简单的API,并且比wrt UITableView更方便-