使用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