我在MonoTouch對話框的MvvmCross實現中使用DateElement。發生異常的原因是DateTimeElement中的方法UpdateDetailDisplay(UITableViewCell單元格)期望單元格參數永不爲空。MvvmCross - 在MonoTouch對話框中使用DateTimeElement時的空異常
protected override void UpdateDetailDisplay(UITableViewCell cell)
{
if (cell.DetailTextLabel != null)
{
cell.DetailTextLabel.Text = FormatDate(Value);
}
}
看來,這個方法是對話視圖的設置過程中調用了三次:
上結合
創建的DateElement一個實例的結果
在構建TableView時調用GetCell。
的電池參數僅出現在事件3
難道我做錯了什麼或應該的方法有參數爲空像StringElement有一個測試?
這是我在viewDidLoad中事件代碼在我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'}}")
},
};
}
我只能夠通過派生我自己從DateElement類用我自己的方法「解決」的問題:
公共類MyDateElement:DateElement { 公共MyDateElement(字符串標題,日期時間日期) :基座(標題,日期) { }
protected override void UpdateDetailDisplay(UITableViewCell cell)
{
if(cell == null)return;
if (cell.DetailTextLabel != null)
{
cell.DetailTextLabel.Text = FormatDate(Value);
}
}
}
登錄到https://github.com/slodge/MvvmCross/issues/13 – Stuart
我認爲這是一種恭維。只是爲了確認,單元格參數始終爲空,直到TableView綁定到源代碼並開始調用source.GetCell(...) –
Phew - 它的意圖是讚美 - 作爲感謝:) – Stuart