我正在使用此代码创建对话框:
SettingsDialog settingDialog = new SettingsDialog ();
RootElement dialog = settingDialog.CreateDialog ();
DialogViewController dv = new DialogViewController (dialog, true);
dv.ViewDissapearing += delegate(object sender1, EventArgs e1) {
// update the values
Config.VendorId = settingDialog.VendorId;
} ;
NavigationController.PushViewController (dv, true);
这是SettingsDialogClass的代码
public class SettingsDialog
{
private EntryElement idElement;
public RootElement CreateDialog ()
{
idElement = new EntryElement ("Vendor Id", string.Empty, Config.VendorId.ToString (CultureInfo.InvariantCulture)){ KeyboardType = UIKeyboardType.NumberPad };
element = new RootElement ("Configuration"){
new Section (){
idElement
} ,
...
}
public string VendorId {
get {
return idElement.Value;
}
}
问题是上面的属性ALWAYS返回旧值,它永远不会更新。 知道为什么吗?
感谢, 伊格纳西奥
答案 0 :(得分:2)
我找到了问题的答案,这个帖子有关键
How can I pass data into MonoTouch.Dialog's delegates?
这一行: 我可以通过在尝试检索它之前调用field.FetchValue()来解决它
所以我将属性修改为
public string VendorId {
get {
idElement.FetchValue();
return idElement.Value;
}
}