1

I create a custom cell PVIssueTypeSectionHeaderCell and add it as a subview for ContentView in the header view with this code:

public override UIView GetViewForHeader(UITableView tableView, nint section)
{
    var cell = (PVIssueTypeSectionHeaderCell)tableView.DequeueReusableCell(HeaderCellKey);
    if(cell == null)
    {
        cell = PVIssueTypeSectionHeaderCell.Create();
    }

    cell.ViewModel = this.GroupedIssueTypesFilter.ElementAt((int)section);

    var headerView = tableView.DequeueReusableHeaderFooterView(HeaderFooterViewKey);

    if (headerView == null)
    {
        headerView = new UITableViewHeaderFooterView(HeaderFooterViewKey);
    }

    headerView.ContentView.AddSubview(cell);

    return headerView;
}

But the custom cell's width does not auto-resize as you could see in these images below.

This is in iPad Landscape mode and in iPhone Portrait mode:

ipad landscape/iphone portrait

While this one is in iPad Portrait mode:

ipad portrait mode

How to make the custom cell automatically resize its width?

currarpickt
  • 2,290
  • 4
  • 24
  • 39

1 Answers1

0

I've finally make it work by returning my custom cell's ContentView directly in GetViewForHeader.

public override UIView GetViewForHeader(UITableView tableView, nint section)
{
    var cell = (PVIssueTypeSectionHeaderCell)tableView.DequeueReusableCell(HeaderCellKey);
    if(cell == null)
    {
        cell = PVIssueTypeSectionHeaderCell.Create();
    }

    cell.ViewModel = this.GroupedIssueTypesFilter.ElementAt((int)section);

    return cell.ContentView;
}
currarpickt
  • 2,290
  • 4
  • 24
  • 39