使用MonoTouch.Dialog
我添加StyledStringElement
元素。
有一个后台任务检索需要更新的详细信息element.Value
有没有办法强制元素在更新后element.Value
更新它的文本?
伊恩
使用MonoTouch.Dialog
我添加StyledStringElement
元素。
有一个后台任务检索需要更新的详细信息element.Value
有没有办法强制元素在更新后element.Value
更新它的文本?
伊恩
如果要逐个元素更新此元素,则可以使用以下内容:
public class MyStyledStringElement {
public void SetValueAndUpdate (string value)
{
Value = value;
if (GetContainerTableView () != null) {
var root = GetImmediateRootElement ();
root.Reload (this, UITableViewRowAnimation.Fade);
}
}
}
一种变体是加载所有内容并更新一次(即在root.Reload
for each 上迭代Element
)。
我已经在 SetValueAndUpdate 方法中添加了“this.PrepareCell (cell); 并且可以工作。但我仍然认为还有另一个更好的选择来检测“caption”的变化并调用 this.PrepareCell (cell);。
public void UpdateCaption(string caption) {
this.Caption = caption;
Console.WriteLine ("actualizando : " + Caption);
UITableViewCell cell = this.GetActiveCell ();
if (cell != null) {
this.PrepareCell (cell);
cell.SetNeedsLayout ();
}
}
另一种更新标签的方法是从单元格中的 DetailTextLabel派生StyledStringElement
或直接刷新:StringElement
class UpdateableStringElement : StringElement
{
public UpdateableStringElement(string name): base (name)
{
}
UILabel DetailText = null;
public void UpdateValue(string text)
{
Value = text;
if (DetailText != null)
DetailText.Text = text;
}
public override UITableViewCell GetCell(UITableView tv)
{
var cell = base.GetCell(tv);
DetailText = cell.DetailTextLabel;
return cell;
}
}
Value
然后,您可以使用以下UpdateValue
方法代替属性:
var element = new UpdateableStringElement("demo");
SomeEventOfYours += delegate {
element.UpdateValue(LocalizedValue);
};