2

I want to use monotouch dialog as not editable data display for some numeric values. But calling DialogViewController.ReloadData does not updates data from binded object.


class AccountFormModel
{
        [Section("Account data", "")]

        [Caption("Balance")]
        public string balance;
}
...
private void InitComponents()
{
            accountFormModel = new AccountFormModel();
            accountFormModel.balance = "TestTestTest";
            bc = new BindingContext(this, accountFormModel, "AccountData");
            dialogViewController = new DialogViewController(bc.Root);
            dialogViewController.Autorotate = true;
}

private void RefreshData()
{
            string b = SomeDatasource.Account.Balance.ToString("N4");
            accountFormModel.balance = "$" + b;
            dialogViewController.ReloadData();
}

Debugging shows that accountFormModel.balance in refreshData method is set to right value, but nothing changes on form in simulator (stays TestTestTest). What i'm doing wrong?

float_dublin
  • 481
  • 1
  • 5
  • 13

1 Answers1

3

DialogViewController when using reflection does the binding once initially, and only when you FetchData() is the data transferred back to your class.

What happens is that the BindingContext will basically create the model from your data (balance in this case) effectively making a copy of your data at this point. When you call ReloadData() this is reloading the data from the copy, and that is why you do not see a change. Although this could be changed to have some method on the BindingContex to repopulate the data, this is not currently the case.

The Reflection API for MonoTouch.Dialog is very limited, I strongly advise you that for anything non-trivial, you use the Elements API. Most of the samples in MonoTouch.Dialog use that API, as it gives you full control of the dialog.

miguel.de.icaza
  • 32,654
  • 6
  • 58
  • 76
  • Hey Miguel, so if I have a lage list (around 1000) of objects that I'm trying to build a large scroll-able list out of, perhaps Dialog is not the best-suited tool? I'm using SyleStringElement extensively, and it takes about 3-4 seconds to render the UITableView (on 3GS device), even after the call to Root.Add(mySection) is complete. I can just as easily override GetCell to accomplish the same thing without using Dialog. Am I understanding your answer here correctly if I interpret it to mean that Dialog is not well-suited to rendering a large list using the Elements API? – NovaJoe Apr 11 '11 at 15:36
  • Still some kind of reload data needs to be made, in case the user chooses "Cancel" for the form. – tofutim Apr 12 '11 at 01:01
  • Never mind. I found what I was doing wrong. I was creating a root element, THEN adding a section to it. The section and all of it's child elements where being created by a LINQ select, but not the root element. Turns out the whole operation is super fast when the creation of the root element is included in the LINQ select...just like in Miguel's example on the MonoTouch.Dialog project page examples. >. – NovaJoe Apr 25 '11 at 17:25