xamarin.ios - Monotouch-Dialog ReloadData 不重新加载数据?

标签 xamarin.ios monotouch.dialog

我想使用单点触控对话框作为某些数值的不可编辑数据显示。但是调用 DialogViewController.ReloadData 不会更新绑定(bind)对象中的数据。


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

调试显示refreshData方法中的accountFormModel.balance设置为正确的值,但模拟器中的表单没有任何变化(仍然是TestTestTest)。我做错了什么?

最佳答案

当使用反射时,DialogViewController 最初会进行一次绑定(bind),并且只有当您使用 FetchData() 时,数据才会传输回您的类。

此时,BindingContext 基本上会根据您的数据(在本例中为余额)创建模型,从而有效地复制您的数据。当您调用 ReloadData() 时,这将从副本中重新加载数据,这就是您看不到更改的原因。虽然这可以更改为在 BindingContex 上使用某种方法来重新填充数据,但目前情况并非如此。

MonoTouch.Dialog 的 Reflection API 非常有限,我强烈建议您对于任何重要的事情,使用 Elements API。 MonoTouch.Dialog 中的大多数示例都使用该 API,因为它使您可以完全控制对话框。

关于xamarin.ios - Monotouch-Dialog ReloadData 不重新加载数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5041521/

相关文章:

xamarin - 如何进行多选 ListView 并获取所选项目?

ios - 无法使用 Xamarin 和 WCF 访问 Web 服务

xamarin.ios - 在单点触控中点击 View 时隐藏选项卡栏和导航栏

xamarin.ios - Monotouch.对话框 : Section font

xamarin.ios - 设置 MonoTouch.Dialog UITableView 位置?

ios - Monotouch AMDeviceInstallApplication 返回 : 0xe8008018

c# - 使用 c#/Xamarin,如何调用类函数?

xamarin.ios - 为 Monotouch-dialog 元素设置自定义字体

c# - 将背景图像添加到 monotouch.dialog View

monotouch.dialog - 选择 RadioGroup 项目时关闭弹出窗口