使用tableView的UITableViewStyleGrouped样式时


它是由两部分组成的,上一个section的footer和下一个section的header。通过以下代码就很明显

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

    UIView *view = [[UIView alloc]init];
    view.frame = CGRectMake(0, 0, ScreenW, 20);

    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, ScreenW, 20)];
    label.center = CGPointMake(ScreenW/2, 20/2);
    label.font = [UIFont systemFontOfSize:12];
    label.backgroundColor = [UIColor redColor];
    label.textAlignment = NSTextAlignmentCenter;
    [view addSubview:label];
    if (section == 0) {
        label.text =  @"最后更新时间:";
    }else
    {
 
 
 
 

 


        label.text =@"配置信息";
    
    }
    
    
    
    return view;

}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc]init];
    view.frame = CGRectMake(0, 0, ScreenW, 20);
    
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, ScreenW, 20)];
    label.center = CGPointMake(ScreenW/2, 20/2);
    label.font = [UIFont systemFontOfSize:12];
    label.backgroundColor = [UIColor blueColor];
    label.textAlignment = NSTextAlignmentCenter;
    [view addSubview:label];
    return view;
}

若想去掉section的footer,仅设置:应将其高度设为比1小很多,但不为0的值,才会有效果

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{

    return 0.001f; }


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM