我想要桌面查看附件按钮,如选择高或取消选择高。
cell.Accessory = UITableViewCellAccessory.None;我想要一个按钮的例子:“全选”当用户触摸这个按钮时,每个单元格的附件都应该勾选。或者我想要“重置”按钮。如果用户触摸此按钮,每个复选标记都会消失,Cell的附件也不会显示任何内容。
发布于 2011-10-31 08:16:00
正如您可能已经发现的那样,使用UITableView有点复杂。但是,有一个用于MonoTouch的奇妙的库,称为MonoTouch.Dialog,它使事情变得简单得多。
下面的示例代码使用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.Dialog)玩得开心!
发布于 2012-11-09 17:13:09
您可以从developer.apple.com中检出this demo。希望能对你有所帮助。
https://stackoverflow.com/questions/7903604
复制相似问题