[英]iOS Auto-resize custom cell width in UITableViewHeaderFooterView.ContentView Subview
I create a custom cell PVIssueTypeSectionHeaderCell
and add it as a subview for ContentView
in the header view with this code: 我创建了一个自定义单元格
PVIssueTypeSectionHeaderCell
并使用以下代码将其作为ContentView
的子视图添加到标题视图中:
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横向模式和iPhone纵向模式下:
While this one is in iPad Portrait mode: 这个是在iPad肖像模式下:
How to make the custom cell automatically resize its width? 如何使自定义单元格自动调整其宽度?
I've finally make it work by returning my custom cell's ContentView
directly in GetViewForHeader
. 我终于通过直接在
GetViewForHeader
返回自定义单元格的ContentView
来使其工作。
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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.