I'm using the DateElement in the MvvmCross implementation of MonoTouch Dialog. The exception happens because the method UpdateDetailDisplay(UITableViewCell cell) in the DateTimeElement expects the cell parameter never to be null.
protected override void UpdateDetailDisplay(UITableViewCell cell)
{
if (cell.DetailTextLabel != null)
{
cell.DetailTextLabel.Text = FormatDate(Value);
}
}
It seems that this method is called three times during the set up of a Dialog view:
as a result of creating an instance of a DateElement
on binding
during the building of the TableView when GetCell is called.
The cell parameter is only present on event 3.
Am I doing something wrong or should the method have a test for the parameter being null like StringElement has?
Here is my code in the ViewDidLoad event in my derivative of MvxTouchDialogViewController:
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'}}")
},
};
}
I have only been able to 'work around' the problem by deriving my own class from DateElement with my own method:
public class MyDateElement : DateElement { public MyDateElement (string caption, DateTime date) : base (caption, date) { }
protected override void UpdateDetailDisplay(UITableViewCell cell)
{
if(cell == null)return;
if (cell.DetailTextLabel != null)
{
cell.DetailTextLabel.Text = FormatDate(Value);
}
}
}