Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Variable row heights in table view

$
0
0

Hi,

I'm trying to get variable row heights to work in table views. I found this excellent post on StackOverflow and have been trying to translate smileyborg's solution into C#. Try as I might, this logic for measuring cell size is always returning zero:

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;
}

Can anyone tell me what I'm doing wrong? I've attached my full project showing what I've done.

Thanks


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>