【发布时间】:2012-06-19 16:16:35
【问题描述】:
我在 MonoTouch Dialog 的 MvvmCross 实现中使用 DateElement。发生异常是因为 DateTimeElement 中的方法 UpdateDetailDisplay(UITableViewCell cell) 期望 cell 参数永远不会为空。
protected override void UpdateDetailDisplay(UITableViewCell cell)
{
if (cell.DetailTextLabel != null)
{
cell.DetailTextLabel.Text = FormatDate(Value);
}
}
在设置Dialog视图的过程中,这个方法好像被调用了3次:
作为创建 DateElement 实例的结果
关于绑定
在构建 TableView 时调用 GetCell。
单元格参数仅出现在事件 3 上。
我是不是做错了什么,或者该方法是否应该像 StringElement 那样测试参数是否为 null?
这是我在 MvxTouchDialogViewController 派生的 ViewDidLoad 事件中的代码:
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
this.Root = new RootElement("Sign-Up")
{
new Section()
{
Bind( new EntryElement("Gender:", "required"), "{'Value':{'Path':'Gender','Mode':'TwoWay'}}"),
Bind( new EntryElement("First name:", "required"), "{'Value':{'Path':'FirstName','Mode':'TwoWay'}}"),
Bind( new EntryElement("Last name:", "required"), "{'Value':{'Path':'LastName','Mode':'TwoWay'}}"),
Bind( new EntryElement("Display name:", "required"), "{'Value':{'Path':'DisplayName','Mode':'TwoWay'}}"),
Bind( new EntryElement("Email:", "required"), "{'Value':{'Path':'Email','Mode':'TwoWay'}}"),
Bind( new EntryElement("Confirm email:", "required"), "{'Value':{'Path':'ConfirmEmail','Mode':'TwoWay'}}"),
Bind( new EntryElement("Password:", "required",null,true), "{'Value':{'Path':'Password','Mode':'TwoWay'}}"),
Bind( new EntryElement("Confirm password:", "required", null,true), "{'Value':{'Path':'ConfirmPassword','Mode':'TwoWay'}}"),
Bind (new DateElement("Date of birth", DateTime.Now), "{'Value':{'Path':'DateOfBirth','Mode':'TwoWay'}}")
},
};
}
我只能通过使用我自己的方法从 DateElement 派生我自己的类来“解决”这个问题:
公共类 MyDateElement : DateElement { 公共 MyDateElement(字符串标题,DateTime 日期) : 基础(标题、日期) { }
protected override void UpdateDetailDisplay(UITableViewCell cell)
{
if(cell == null)return;
if (cell.DetailTextLabel != null)
{
cell.DetailTextLabel.Text = FormatDate(Value);
}
}
}
【问题讨论】:
标签: c# xamarin.ios monotouch.dialog mvvmcross