空白的第一个UITableView节头 [英] Blank first UITableView section header

查看:92
本文介绍了空白的第一个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;

这篇关于空白的第一个UITableView节头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆