MonoTouch.Dialog:响应RadioGroup中选择 [英] MonoTouch.Dialog: Responding to a RadioGroup Choice
本文介绍了MonoTouch.Dialog:响应RadioGroup中选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个对话由MonoTouch.Dialog创建。有医生的单选按钮组在列表中:
I have a Dialog created by MonoTouch.Dialog. There is a list of Doctors in a radio group:
Section secDr = new Section ("Dr. Details") {
new RootElement ("Name", rdoDrNames){
secDrNames
}
我想在一旦医生已被选定的代码更新元素
。什么是通知的最佳途径,一个放射性元素
已被选中?
I wish to update an Element
in the code once a Doctor has been chosen. What's the best way to be notified that a RadioElement
has been selected?
推荐答案
创建自己的放射性元素
这样的:
class MyRadioElement : RadioElement {
public MyRadioElement (string s) : base (s) {}
public override void Selected (DialogViewController dvc, UITableView tableView, NSIndexPath path)
{
base.Selected (dvc, tableView, path);
var selected = OnSelected;
if (selected != null)
selected (this, EventArgs.Empty);
}
static public event EventHandler<EventArgs> OnSelected;
}
的注:不,如果你想有使用静态事件多个无线电集团的
然后创建一个 rootElement的
使用这种新型的,如:
Then create a RootElement
that use this new type, like:
RootElement CreateRoot ()
{
StringElement se = new StringElement (String.Empty);
MyRadioElement.OnSelected += delegate(object sender, EventArgs e) {
se.Caption = (sender as MyRadioElement).Caption;
var root = se.GetImmediateRootElement ();
root.Reload (se, UITableViewRowAnimation.Fade);
};
return new RootElement (String.Empty, new RadioGroup (0)) {
new Section ("Dr. Who ?") {
new MyRadioElement ("Dr. House"),
new MyRadioElement ("Dr. Zhivago"),
new MyRadioElement ("Dr. Moreau")
},
new Section ("Winner") {
se
}
};
}
[更新]
下面是本放射性元素的更现代的版本:
Here is a more modern version of this RadioElement:
public class DebugRadioElement : RadioElement {
Action<DebugRadioElement, EventArgs> onCLick;
public DebugRadioElement (string s, Action<DebugRadioElement, EventArgs> onCLick) : base (s) {
this.onCLick = onCLick;
}
public override void Selected (DialogViewController dvc, UITableView tableView, NSIndexPath path)
{
base.Selected (dvc, tableView, path);
var selected = onCLick;
if (selected != null)
selected (this, EventArgs.Empty);
}
}
这篇关于MonoTouch.Dialog:响应RadioGroup中选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文