UITableView setTableHeaderView

我遇到了一个问题,当一个View是tableview的tableHeaderview时,我把View重新嵌套一层重新设置给tableHeaderview,这个View不展示 代码如下:

UIView *view = [UIView new]; tableView.tableHeaderview = view;

UiView *otherView = [UIview new]; otherView addSubview:view]; tableView.tableHeaderview = otherView;

这个时候view不展示了。

根据调用栈看,设置tableHeaderview后,view执行了一次removeFromSuperview,从otherView中消失了。

所以想了解一下,当设置新的tableHeaderview,对旧的HeaderView是怎么处理的?

Answered by DTS Engineer in 788561022

Did you try to give the your view an explicit frame, or set up appropriate auto layout constraints for it? I believe your view should show up in the table header area if having an appropriate size.

Did you try to give the your view an explicit frame, or set up appropriate auto layout constraints for it? I believe your view should show up in the table header area if having an appropriate size.

UITableView setTableHeaderView
 
 
Q