【发布时间】:2015-06-30 21:18:51
【问题描述】:
我想重写 GetHeightForRow 方法,因此当滚动到特定单元格(行)时,我的滚动效果很好。
我发现这个例子here 运行良好。因为这部分代码:
public override float GetHeightForRow(UITableView tableView, NSIndexPath indexPath)
{
if (this.offscreenCell == null)
{
this.offscreenCell = new ItemCell();
}
var cell = this.offscreenCell;
cell.UpdateFonts();
var item = this.model.Items[indexPath.Row];
cell.Title = item.Title;
cell.Body = item.Body;
cell.SetNeedsUpdateConstraints();
cell.UpdateConstraintsIfNeeded();
cell.Bounds = new RectangleF(0, 0, this.TableView.Bounds.Width, this.TableView.Bounds.Height);
cell.SetNeedsLayout();
cell.LayoutIfNeeded();
var height = cell.ContentView.SystemLayoutSizeFittingSize(UIView.UILayoutFittingCompressedSize).Height;
height += 1;
return height;
}
尝试将其翻译到我的 MvvmCross 项目中,例如:
public override float GetHeightForRow(UITableView tableView, NSIndexPath indexPath)
{
if (this.offscreenCell == null)
{
this.offscreenCell = new ItemCell();
}
var cell = this.offscreenCell;
cell.DataContext = this.model.Items[indexPath.Row];
cell.SetNeedsUpdateConstraints();
cell.UpdateConstraintsIfNeeded();
cell.Bounds = new RectangleF(0, 0, this.TableView.Bounds.Width, this.TableView.Bounds.Height);
cell.SetNeedsLayout();
cell.LayoutIfNeeded();
var height = cell.ContentView.SystemLayoutSizeFittingSize(UIView.UILayoutFittingCompressedSize).Height;
height += 1;
return height;
}
但无论如何它总是返回 36.5。有什么制作方法吗?
谢谢你,
【问题讨论】:
标签: ios dynamic xamarin height mvvmcross