我已经尝试了所有可能的方法。我在那个自定义单元格中使用了 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();
}
最佳答案
您是否尝试过使用 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/