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

标签 iphone ios xamarin.ios monotouch.dialog

我有一个源自 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/

相关文章:

ios - 在youtube-ios-player-helper中设置 “origin”会破坏编程功能

iphone - SetVisibleMapRect总是去北冰洋

xcode - Monotouch 5 之后 XIB 文件的使用

iPhone上传图片速度建议

iphone - 在屏幕顶部显示文本字段的键盘

iPhone iOS 如何以编程方式创建色调和阴影?

ios - Sprite 有时会消失 [Sprite Kit]

ios - 将 Base64 NSString 转换为 UIImage?

ios - 将委托(delegate)分配给 View Controller 以外的其他对象时未调用 SFSafariViewControllerDelegate 方法

c# - Xamarin Forms Visual Studio 2015 HttpClient 请求在 iOS 上不起作用