2012-03-26 11 views
2

Ich bin ein Anfänger in MonoTouch und MonoTouch.Dialog. Ich versuche, MT Dialog zu verwenden, aber ich kann nicht verstehen, wie man Daten rein und raus bekommt.MonoTouch.Dialog, wie man Daten aus dem Dialog

Lassen Sie uns sagen, ich habe Event-Klasse:

class Event { 
bool type {get;set;} 
string name {get;set;} 
} 

Und ich will es bearbeiten Dialogdefinition:

 return new RootElement ("Event Form") { 

     // string element 
      new Section ("Information"){ 
       new EntryElement ("Name", "Name of event", ""), 
       new RootElement ("Type", new RadioGroup (0)){ 
        new Section(){ 
         new RadioElement ("Concert"), 
         new RadioElement ("Movie"), 
         new RadioElement ("Exhibition"), 
         new RadioElement ("Sport") 
        } 

       } 
      }, 

Wie kann ich passieren Daten zu und von dieser Form? (Unter Verwendung von Low-Level-API nicht Reflexion, die unterstützt Bindung)

Antwort

0

Sie können so etwas tun:

//custom class to get the Tapped event to work in a RadioElement 
    class OptionsRadioElement: RadioElement 
    { 
      public OptionsRadioElement(string caption, NSAction tapped): base(caption) 
      { 
       Tapped += tapped; 
      } 
    } 

//Custom Controller 
public class MyController: DialogViewController 
{ 
    private readonly RadioGroup optionsGroup; 
    private readonly EntryElement nameField; 



    public MyController(): base(null) 
    { 
     //Note the inline assignements to the fields 
     Root = new RootElement ("Event Form") { 
      new Section ("Information"){ 
      nameField = new EntryElement ("Name", "Name of event", ""), 
      new RootElement ("Type", optionsGroup = new RadioGroup (0)){ 
       new Section(){ 
        new OptionsRadioElement("Concert", OptionSelected), 
        new OptionsRadioElement("Movie", OptionSelected), 
        new OptionsRadioElement("Exhibition", OptionSelected), 
        new OptionsRadioElement("Sport", OptionSelected) 
       } 

      } 
     }; 
    } 

    private void OptionSelected() 
    { 
     Console.WriteLine("Selected {0}", optionsGroup.Selected); 
    } 


    public void SetData(MyData data) 
    { 
      switch(data.Option) 
      { 
       case "Concert: 
        optionsGroup.Selected = 0; 
        break; 
       case "Movie": 
        optionsGroup.Selected = 1; 
        break; 
        //And so on.... 
       default: 
        optionsGroup.Selected = 0; 
        break; 
      } 
      nameField.Value = data.Name; 
      ReloadData(); 

    } 
} 
3

Sehr einfach, weisen die Zwischenwerte zu Variablen:

Section s; 
SomeElement e; 

return new RootElement ("Foo") { 
    (s = new Section ("...") { 
     (e = new StringElement (...)) 
    }) 
}; 
+0

Was ist, wenn Sie sind die Elemente aus der Datenbank wie in http://stackoverflow.com/questions/14866188/monotouch-dialog-generate-from-db-and-retain-values ​​ausgeben? – BRogers

Verwandte Themen