隐藏特定UITableView部分的TableView标题视图

时间:2013-07-28 20:59:13

标签: iphone ios objective-c uitableview tableview

所以我有这个Tableview的几个部分,(3)确切地说。我希望有第2和第3部分的标题,而不是第一部分..

继承我所做的事情:

- (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 :(得分:2)

如果部分== 0,您仍然将tempView设置为UIView的新实例并返回该值,您只是不设置标签的标题。同样,如您所知,对于第0部分,您应该为tableView:heightForHeaderInSection:返回0。

答案 1 :(得分: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

相关问题