gpt4 book ai didi

iOS UITableView.AutomaticDimension 不工作

转载 作者:行者123 更新时间:2023-11-28 13:32:20 25 4
gpt4 key购买 nike

我已经尝试了所有可能的方法。我在那个自定义单元格中使用了 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/

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