【问题标题】:MonoTouch Dialog elements are not updating/repainting themselvesMonoTouch 对话框元素不会自行更新/重新绘制
【发布时间】:2012-03-20 13:25:22
【问题描述】:

我在一个部分中有以下内容:

            _favElement = new StyledStringElement (string.Empty);
            _favElement.Alignment = UITextAlignment.Center;

            if (_room.IsFavourite) {
                _favElement.Image = UIImage.FromBundle ("Images/thumbs_up.png");
                _favElement.Caption = "Unmark as Favourite";
            } else {
                _favElement.Image = null;
                _favElement.Caption = "Mark as Favourite";
            }

            _favElement.Tapped += favElement_Tapped;

然后,当我按下元素时,我希望发生以下情况:

        private void favElement_Tapped ()
        {
            if (_room.IsFavourite) {
                _favElement.Image = null;
                _favElement.Caption = "Mark as Favourite";
            } else {
                _favElement.Image = UIImage.FromBundle ("Images/thumbs_up.png");
                _favElement.Caption = "Unmark as Favourite";
            }   

            _room.IsFavourite = !_room.IsFavourite;
        }

但是,当点击元素时,实际元素中的图像和文本不会改变。是否有刷新方法或必须调用的东西?我也尝试过更改 Tapped 上的附件,但没有任何变化。后面的属性确实反映了正确的值。

【问题讨论】:

    标签: xamarin.ios monotouch.dialog


    【解决方案1】:

    重新加载UITableView 的替代方法是使用如下代码重新加载Element(复制自Touch.Unit):

    if (GetContainerTableView () != null) {
        var root = GetImmediateRootElement ();
        root.Reload (this, UITableViewRowAnimation.Fade);
    }
    

    【讨论】:

      【解决方案2】:

      假设你的代码在 DialogViewController 中,添加这个

      this.ReloadData();
      

      但在您的情况下,我建议您使用 BooleanImageElement

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-30
      • 1970-01-01
      • 2016-06-11
      相关资源
      最近更新 更多