gpt4 book ai didi

iphone - StringElement 派生控件不更新标题

转载 作者:行者123 更新时间:2023-12-01 19:13:36 25 4
gpt4 key购买 nike

我有一个源自 MT.D StringElement 的控件.可以使用空白/空 Caption 创建元素当用户将文本添加到不同的控件时,它随后会更新。 Caption是 MT.D Element 中的一个字段类并设置它不会自动更新关联的控件。因此,为了尝试更新控件,我创建了一个更新基本字段的属性,然后尝试更新控件。

public new string Caption {
get {
return base.Caption;
}
set {
base.Caption = value;
var cell = GetActiveCell();
if (cell != null) {
cell.TextLabel.Text = value;
}
}
}

遗憾的是,它没有使用新值更新 UI。使用调试器,我可以看到它正确设置了新值,但没有显示文本。如果我使用非空白 Caption 创建控件那么它就正确显示了。我使用类似的方法来更新控件的 ImageView哪个工作正常。
private void SetUiState(){
var cell = this.GetActiveCell();
if (cell != null) {
var imgView = cell.ImageView;
if (imgView != null) {
imgView.Image = _isEnabled ? _enabledImage : _disabledImage;
}
cell.SelectionStyle = _isEnabled ? UITableViewCellSelectionStyle.Blue : UITableViewCellSelectionStyle.None;
}
}

知道为什么它不适用于单元格的 TextLabel ?

最佳答案

我以前见过这个,单元格需要重新布局,因为需要更改 TextLabel 的框架以适应文本的更改。

public class TestElement : StringElement
{
public TestElement() : base("")
{

}

public new string Caption {
get
{
return base.Caption;
}

set
{
base.Caption = value;
var cell = GetActiveCell();
if (cell != null)
{
cell.TextLabel.Text = value;
cell.SetNeedsLayout();
}
}
}
}

关于iphone - StringElement 派生控件不更新标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14792908/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com