我有一个 UIViewController
,其中嵌入了多个 UITableView
。对于某些表格,我需要显示带有多个标签的自定义标题 View 。对于其他表格,我根本不想显示标题(也就是说,我希望 myTable2
中的第一个单元格位于 myTable2
框架的顶部>).这大致是我所拥有的:
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
if (tableView == self.myTable1)
// Wants Custom Header
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0,0,tableView.contentSize.width,20);
// ... Do stuff to customize view ...
return view;
}
elseIf (tableView == self.myTable2)
// Wants No header
{
return nil;
// also tried
// return [[UIView alloc] initWithFrame:CGRectMake(0,0,0,0)];
// but that didn't work either
}
}
这对自定义标题非常有效,但对于我不需要任何标题的表格,它显示一个白色框。我认为 return nil;
会阻止为该表显示任何标题。这个假设正确吗?还有其他东西可以覆盖吗?我怎样才能让它不显示任何内容?
最佳答案
每当您实现 viewForHeaderInSection
方法时,您还必须实现 heightForHeaderInSection
方法。确保为没有标题的部分的高度返回 0
。
关于ios - viewForHeaderInSection - 没有标题返回什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21764786/