2012-09-08 141 views
1

我是monotouch.dialog的初學者。 我試圖從radiogroup中獲得一個帶有標題和值作爲經典下拉列表的覆蓋radioelement的值!MonoTouch.Dialog如何從radiogroup獲取數據

但問題是檢測事件ONSELECT

CODE MYRADIOELEMENT的

public class MyRadioElement : RadioElement 
    { 

    private string Caption{get; set;} 
    private int ID{get; set;} 

     public MyRadioElement(string caption, int id, NSAction selected): base(caption, id) 
     { 
      Caption = caption; 
      ID = id; 

      OnSelected += selected; 
     } 

    public override void Selected (DialogViewController dvc, UITableView tableView, NSIndexPath path) 
    { 
     base.Selected (dvc, tableView, path); 
     var selected = OnSelected; 
     if (selected != null) 
      selected(); 
    } 

    public event NSAction OnSelected; 

} 

rootElement的代碼

var rootSex = new RootElement ("SEX", 
sexUser = new RadioGroup ("", -1)){new Section ("INSERT SEX"){ 
from n in Def.Get_Sexes() 
select (Element) new MyRadioElement (n.Descr, n.ID, ????delegate?????)} 
}; 

我會用委託來調用選擇的事件,但它給我一個轉換錯誤...

爲什麼? 感謝

回答

4

這一個應該工作

class MyRadioElement: RadioElement 
{ 
    private Action<MyRadioElement> selected; 

    public MyRadioElement(string caption, int id, Action<MyRadioElement> selected): base(caption, id) 
    { 
     this.selected = selected; 
    } 


    public override void Selected (DialogViewController dvc, UITableView tableView, NSIndexPath path) 
    { 
     base.Selected (dvc, tableView, path); 

     if (this.selected != null) 
        this.selected(this); 

    } 
} 

然後您可以創建元素

new MyRadioElement("Caption", 2, MyMethod) 

的MyMethod會是什麼樣子

private void MyMethod(MyRadioElement e) 
{ 

} 
+0

坦克傑米 但我需要選擇對象,2屬性:標題和ID 選擇(元件)新MyRadioElement(n.Descr,n.ID,()=> \t \t \t \t \t \t {\t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t}) – user1592476

+0

我剛剛沒有訪問mt對話框,但RadioGroup.Selected是否允許您訪問這些屬性?如果需要,您可以將其轉換爲您自己的類型。 – Jamie

+0

對不起,但我不明白我該怎麼辦,你能舉個例子嗎? – user1592476