我的项目中有两个UITableView,我使用该方法为一个表提供自定义标题:
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
if(tableView.tag == 3)
{
SectionInfo *array = [self.sectionInfoArray objectAtIndex:section];
if (!array.sectionView)
{
NSString *title = array.groupdeck.groupTitle;
array.sectionView = [[SectionView alloc] initWithFrame:CGRectMake(0, 0, tblData.bounds.size.width, 45) WithTitle:title Section:section delegate:self];
}
return array.sectionView;
}
else{
return 0;
}
return 0;
}
它为表格提供标题为3的表格:
但它正在给其他表提供默认标头,甚至return 0
其他条件如:
我错过了什么?
答案 0 :(得分:2)
它可能默认为默认标头,因为您返回了0
。请尝试返回nil
。
答案 1 :(得分:2)
尝试:
otherTable.sectionHeaderHeight = 0.0;
您无需做任何其他事情。
或者:
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
if(tableView.tag == 3)
{
//Required height.
}
else
{
return 0.0;
}
}
答案 2 :(得分:0)
参考Apple文档中的参考文档
// custom view for header. will be adjusted to default or specified header height
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;
显示默认标题,分组表格的高度为22 ,非强化表格的 10 。
此外,如果要在UITableView
中显示的视图高度超过上述值,则还必须使用UITableView
委托方法
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;