iOS UITableView.AutomaticDimension 不工作

标签 ios swift xamarin.ios

我已经尝试了所有可能的方法。我在那个自定义单元格中使用了 UITableView 我有两个标签。如果文本更多,我想自动调整该行的大小。它没有发生。请帮助任何人知道答案。请检查代码和截图。

注意:此代码位于 Xamrin.iOS 中。你也可以快速回答

[Export("tableView:estimatedHeightForRowAtIndexPath:")]
        public nfloat EstimatedHeight(UITableView tableView, NSIndexPath indexPath)
        {
            return UITableView.AutomaticDimension;
        }
        [Export("tableView:heightForRowAtIndexPath:")]
        public nfloat GetHeightForRow(UITableView tableView, NSIndexPath indexPath)
        {
            return UITableView.AutomaticDimension;
        }



public override void ViewWillAppear(bool animated)
        {
            base.ViewWillAppear(animated);
            notificationTableView.EstimatedRowHeight = 200;
            notificationTableView.RowHeight = UITableView.AutomaticDimension;

            notificationTableView.ReloadData();
            notificationTableView.LayoutIfNeeded();
        }

Please click here for screen shot

Label1 constraint

Label2 constraint

最佳答案

您是否尝试过使用 getter 和 setter 方法为单元格赋值?

    public string DescriptionTxt
    {
        get { return labelCustomerDescription.Text; }
        set { labelCustomerDescription.Text = value; }
    }

如果需要,您还可以在将文本分配给单元格后尝试对单元格进行布局。

cell.SetNeedsDisplay();
cell.LayoutIfNeeded();

关于iOS UITableView.AutomaticDimension 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57161504/

相关文章:

ios - Xamarin 无法在 iPhone 模拟器上运行 iOS 应用程序 - 不支持 386 架构

ios - UIScrollView 可以缩放,但不能平移

android - 在 Dart/Flutter 中传递返回对象的函数不起作用

ios - Swift 选择器 - 发送到实例的无法识别的选择器

ios - MvvMCross 向后导航多个 View 模型/截断导航堆栈

c# - Monotouch.Dialog 两个表

ios - 自定义分段控件宽度代码没有故意工作

iphone - 在 iphone 上使用正则表达式捕获括号

json - 从这里抛出的错误没有得到处理,因为封闭的 catch 并不详尽

ios - 在所需的初始化中从 NSCoder 获取属性(编码器 aDecoder : NSCoder)