[英]iOS Auto-resize custom cell width in UITableViewHeaderFooterView.ContentView Subview
我創建了一個自定義單元格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;
}
但是,您可以在下面的圖片中看到,自定義單元格的寬度不會自動調整大小。
這是在iPad橫向模式和iPhone縱向模式下:
這個是在iPad肖像模式下:
如何使自定義單元格自動調整其寬度?
我終於通過直接在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.