2013-07-28 35 views
0

隐藏TableViewHeaderView所以我有这个泰伯维有几节,(3)要准确。我希望这是对第2和第3,而不是第一部分头..特定的TableView部分

我所做的继承人什么:

- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 
{ 
    NSString *sectionName; 

    UIView *tempView; 
    tempView = [[UIView alloc]initWithFrame:CGRectMake(0,0,300,20)]; 
    tempView.backgroundColor=[UIColor grayColor]; 

    UILabel *tempLabel = [[UILabel alloc]initWithFrame:CGRectMake(10,0,300,20)]; 
    tempLabel.backgroundColor = [UIColor clearColor]; 
    tempLabel.shadowColor = [UIColor blackColor]; 
    tempLabel.shadowOffset = CGSizeMake(0,2); 
    tempLabel.textColor = [UIColor whiteColor]; //here you can change the text color of header. 
    tempLabel.font = [UIFont fontWithName:@"Helvetica" size:14.0f]; 


    switch (section) 
    { 
      break; 
     case 1: 
     { 
      sectionName = NSLocalizedString(@"Information", @"Information"); 
      tempLabel.text = sectionName; 
      [tempView addSubview:tempLabel]; 
     } 
      break; 

     case 2: 
     { 
      sectionName = NSLocalizedString(@"Tools", @"Tools"); 
      tempLabel.text = sectionName; 
      [tempView addSubview:tempLabel]; 
     } 
      break; 

    } 
    return tempView; 
} 

我就需要做什么困惑...继承人一个图片是怎么回事:TableViewHeader

回答

2

在部分== 0的情况下,您仍将tempView设置为UIView的新实例并返回该值,您只是不设置标签的标题。另外,作为你学习,你应该为tableView:heightForHeaderInSection:返回0为0节

0

所以,当我在写这个问题我凸轮的结论......但也许它不是更有效率?

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section 
{ 
    CGFloat headerheight = 20.0; 

    switch (section) 
    { 
     case 0: { headerheight = 0.0; } break; 
     case 1: { headerheight = 20.0; } break; 
     case 2: { headerheight = 20.0; } break; 
    } 
    return headerheight; 
} 

如果有人对我如何不需要实现这个tableview委托方法有什么建议,请大声说出来。我觉得像我刚才难道不需要返回查看指定部分,而不是说一个章节标题为0。但我不完全确定的那一刻,这个问题就解决了,但也许不能正确解决了吗?

下面有一个解决方案的结果的照片。

Solution Pic

+0

是的,你也应该为'的tableView返回0:heightForHeaderInSection:',但它是最好的,如果你还修改了'viewForHeaderInSection'到的情况下返回'nil'该部分== 0,待办事项它在该方法的顶部。 –

+0

你认为你可以为我实现部分== 0的情况?我实现了viewForHeaderInSection方法像这样,开关(部分) { 情况下0: { tableView.tableHeaderView =零; } break;它没有工作:( – jsetting32

+0

只需添加这是该方法的第一行:'如果(部分== 0)返回零;'如果你这样做,你不会需要一个'情况0'(和也。 ,你不会有创建一个标题视图的开销,你最终会放弃)。 –