MonoTouch.Dialog how to get data from dialog

时光毁灭记忆、已成空白 提交于 2019-12-06 09:14:01

Very easy, assign the intermediate values to variables:

Section s;
SomeElement e;

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

You can do something like this:

    //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();

    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!