0

I am trying to implement a Settings dialog for iOS using MonoTouch and the DialogViewController.

The class below contains some public properties, and a method to get a DialogViewController for it.

The problem is that when the view disappears, the string value in thisName.Value is null (I have of course filled in something in the text field).

Why?

    public class Settings
    {
        public string Name { get; set; }

        public  int MagicNumber { get; set; }

        public bool ThisIsEnabled{ get; set; }

        public Settings ()
        {
            var defaults = NSUserDefaults.StandardUserDefaults;
            Name = defaults.StringForKey ("name");
            ThisIsEnabled = defaults.BoolForKey("thisisenabled");
            MagicNumber = defaults.IntForKey ("123");
        }

        public UIViewController GetViewController ()
        {
            var thisBoolean = new BooleanElement ("This boolean", ThisIsEnabled);
            var thisName = new EntryElement ("Name", "name", Name);
            thisName.KeyboardType = UIKeyboardType.ASCIICapable;

            var root = new RootElement ("Options"){
                new Section (){thisBoolean,thisName}
            };

            var dv = new DialogViewController (root, true){Autorotate= true};
            dv.ViewDissapearing += delegate {
                ThisIsEnabled = thisBoolean.Value; // <== This works
                Name = thisName.Value; // <== This is NULL

                var defaults = NSUserDefaults.StandardUserDefaults;
                defaults.SetBool (ThisIsEnabled, "thisisenabled");
                defaults.SetString (Name, "name");
            };
            return dv;
        }
    }
}
Magnus Johansson
  • 28,010
  • 19
  • 106
  • 164

1 Answers1

0

the current release of MT.D will not "save" a field's value until the user navigates away from it. This may be what you are seeing.

This behavior has been fixed, but has not been released yet.

Jason
  • 86,222
  • 15
  • 131
  • 146