我想重寫GetHeightForRow方法,因此當滾動到特定單元格(行)時,我的滾動工作正常。MvvmCross中的動態單元格高度
我發現這個例子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沒有問題的。任何線索如何使它?
感謝的問候,
它會導致我面臨同樣的問題。如果我想要一個動態高度視圖控制器單元格,我將不得不計算它在thingdelegateflowlayout.getsizeforitem ...問題是如何計算它與mvxtableviewcell ... –