您的位置:首页 > 产品设计 > UI/UE

IOS之UITableView的header显示问题

2015-07-01 12:02 836 查看
最近在攻克新项目,发现一个不一样的地方,觉得也许是apple的小bug吧,不确定呢。

情景

使用UITableView展示列表元素信息,使用grouped方式,设置section的header,奇怪的是不显示section=0的时候的header。

发现

我是通过xib配置的UITableView,在tableview的section height中修改了header的参数为30,footer为1



而后,代码为

//setion数量
static const int VCInfoSectionCount = 5;
//用户账户信息
static const int VCUserInfoSection = 0;
//微信信息
static const int VCWeiXinInfoSection = 1;
//钱包信息
static const int VCWalletInfoSection = 2;
//邀请信息
static const int VCInviteInfoSection = 3;
//设置信息
static const int VCSettingInfoSection = 4;

...

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10.0f, 5.0f, tableView.width, 20.0f)];
if (section == 0) {
NSLog(@"出现section = 0");
}

if (section == VCUserInfoSection) {
titleLabel.text = @"账号信息";
}else if (section == VCWeiXinInfoSection){
titleLabel.text = @"微信信息";
}else if (section == VCWalletInfoSection){
titleLabel.text = @"钱包信息";
}else if (section == VCInviteInfoSection){
titleLabel.text = @"邀请信息";
}else if (section == VCSettingInfoSection){
titleLabel.text = @"基本设置";
}
titleLabel.textColor = [UIColor blueColor];
titleLabel.backgroundColor = [UIColor orangeColor];
return titleLabel;
}


发现,显示效果,顶部没有出现预计中的账号信息header,擦,奇怪了,日志不输出出现section = 0。

而后,我又增加了代码

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 30.0f;
}


这时候,日志输出section = 0,并且显示出账号信息header了。

照理说,我xib中已经设置了header的height了啊,而且其他section的header显示出来了,但是就是第一个不显示出来,邪门中。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息