我試圖在設置完DVC後設置它時,在UI中更新StringElement的'Value'來更新。爲什麼MonoTouch.Dialog對某些元素選項使用公共屬性,對其他元素使用公共屬性
e.g:
public partial class TestDialog : DialogViewController
{
public TestDialog() : base (UITableViewStyle.Grouped, null)
{
var stringElement = new StringElement("Hola");
stringElement.Value = "0 Taps";
int tapCount = 0;
stringElement.Tapped +=() => stringElement.Value = ++tapCount + " Taps";
Root = new RootElement("TestDialog")
{
new Section("First Section")
{
stringElement,
},
};
}
}
然而StringElement.Value僅僅是一個公共領域,當Element.GetCell稱爲初始化過程中只寫入UICell。
爲什麼不是一個屬性,與邏輯在二傳手更新UICell(像大多數元素,例如EntryElement.Value):
public string Value
{
get { return val; }
set
{
val = value;
if (entry != null)
entry.Text = value;
}
}
編輯:
我做了我自己的版本的StringElement
,從Element
導出(基本照搬了source code from here逐字)
然後我把它改爲採取類範圍的參考GetCell
創建的,而不是功能SCOP細胞編輯。然後改變了Value
字段屬性:
public string Value
{
get { return val; }
set
{
val = value;
if (cell != null)
{
// (The below is copied direct from GetCell)
// The check is needed because the cell might have been recycled.
if (cell.DetailTextLabel != null)
cell.DetailTextLabel.Text = Value == null ? "" : Value;
}
}
}
它工作在最初的測試。然而,我不確定是否允許引用單元格,其他元素似乎都沒有這樣做(它們僅引用控件放置在單元格中的引用)。是否有可能基於一個MonoTouch.Dialog.Element
實例創建多個'live'*單元?
*我說現場指示單元目前是活動用戶界面的一部分。從一個子對話框導航回到對話框時,我注意到GetCell方法再次被調用,並且基於元素創建了一個新的單元,但這仍然是元素和活動單元之間的一個1-1。