空白的第一个UITableView节头

问题描述:

我的UITableView中有2个部分。我希望我的第一个标题是不存在,没有空间,没有任何东西。第一个单元格触摸屏幕顶部。我想要第二部分的自定义部分标题。

I have 2 sections in my UITableView. I'd like my first header to be nonexistant, no space, no nothing. The first cell touches the top of the screen. I'd like a custom section header for my second section.

如果我不使用 - (UIView *)tableView,我可以这样做:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 但是当我使用这个方法时,第一部分会出现一个空白标题视图。我做错了什么?

I can do this if I don't use - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section but the moment I use this method a blank header view appears in the first section. What am I doing wrong?

- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    if (!section == 0){
        UIView *header = [[UIView alloc]initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30.0f)];
        UILabel *label = [[UILabel alloc]initWithFrame:[header frame]];
        [label setText:@"Test Header"];
        [header addSubview:label];

        return header;
    }
    else{
        // This apparently causes a header to appear in section 0. 
        // Without this entire method it works fine- but it means I can't customize
        // the header.
        return nil;
    }



}


寻找

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger )

UITableView的方法

第一部分你可以返回0;