解决在tableView返回组标题直接返回字符串,带来的不便设置组标题样式的问题解决办法,设置尾部标题和此类似


 // 返回组头部view的高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ 
    return 20;
}
 
//返回每组头部view  - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *headerView = [[UIView alloc]init];
    headerView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    UILabel *label = [[UILabel alloc]init];
    label.textColor = [UIColor grayColor];
    label.font = [UIFont systemFontOfSize:13];
    label.frame = CGRectMake(15, 0, 100, 20);
    [headerView addSubview:label];
   if (section == 0) {
        label.text = @"第0组title";
    }else{
        label.text = @"第1组title";
    }
    return headerView;
}

封装 UITableViewHeaderFooterView 也像tableViewCell一样也可以循环利用  自定义 UITableViewHeaderFooterView


+ (instancetype)headerFooterViewWithTabelView:(UITableView *)tableView{
    BSHeaderFooterView *headerFooterView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:headerIdentifier];
    if (headerFooterView == nil) {
        headerFooterView = [[BSHeaderFooterView alloc]initWithReuseIdentifier:headerIdentifier];
    }
    return headerFooterView;
}

 - (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
            self.contentView.backgroundColor = [UIColor groupTableViewBackgroundColor];
            UILabel *label = [[UILabel alloc]init];
            label.textColor = [UIColor grayColor];
            label.font = [UIFont systemFontOfSize:13];
            label.frame = CGRectMake(13, 0, 100, 20);
            [self addSubview:label];
            self.label = label;
    }
        return self;
}
 
//接收外界传进来的字符串并赋值 - (void)setTitle:(NSString *)title{
    _title = [title copy];
    self.label.text = title;
}
 
//返回组头部view方法 - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    BSHeaderFooterView *headerFooter = [BSHeaderFooterView headerFooterViewWithTabelView:tableView];
    if (section == 0) {
        headerFooter.title = @"第0组title";
    }else{
        headerFooter.title = @"第1组title";
    }
    return headerFooter;
}

iOS中tableView组头部或尾部标题的设置的更多相关文章

  1. 如何在HTML不同的页面中,共用头部与尾部?

    一.asp语言和PHP语言 首先制作一个头部文件head.asp,或者一个底部文件foot.asp.如主页是index.asp,调用头部代码是在index.asp文件代码的开始位置(第一个标记后面,& ...

  2. IOS中TableView的用法

    一.UITableView 1.数据展示的条件 1> UITableView的所有数据都是由数据源(dataSource)提供的,所以要想在UITableView展示数据,必须设置UITable ...

  3. iOS中TableView小技巧

    摘要: TableView是ios开发中经经常使用到的控件,这里统一记录一下开发中遇到的经常使用小技巧,不断探索更新.也希望大家能够告诉我很多其它经常使用的小技巧啦~一起进步 1.去除多余的列表线条 ...

  4. IOS中tableView每组的头部控件、通过tableView的代理方法控制某一行的cell能否达到高亮选中状态

    一.tableView每组的头部控件 1.控件宽度默认就是tableView的宽度 2.控件高度由下面的代理方法决定 - (CGFloat)tableView:(UITableView *)table ...

  5. IOS中TableView的使用(1) -创建一个简单的tableView

    创建一个简单的tableView: #import <UIKit/UIKit.h> /*tableView 一定要遵守这两个协议: UITableViewDataSource,UITabl ...

  6. ios中tableview的移动添加删除

    // // MJViewController.m // UITableView-编辑模式 // // Created by mj on 13-4-11. // Copyright (c) 2013年 ...

  7. ios中tableview网封装(viewcontroller封装)常用的

    下载地址 http://pan.baidu.com/share/link?shareid=3657500168&uk=923776187 使用框架 1:asIHttpRequest库 2;SB ...

  8. ios中tableview侧栏的折叠

    #import "ViewController.h" #define Ksmall 40.0f #define Klarge 80.0f #define KNoOpen @&quo ...

  9. IOS中Label根据上个label的内容设置下个label的frame

    #import "ViewController.h" @interface ViewController () @property(nonatomic,strong)UILabel ...

随机推荐

  1. 让 Google Test 出错时断点

    Google Test 缺省是出错退出. 如果最后的出错行在系统库中,那就没什么帮助. 如果是调试运行,直接退出根本就不知道哪里出错了. 后来添加了一个运行参数: --gtest_break_on_f ...

  2. Ubuntu 15.10下Qt5的安装实战

    写照篇博客的目的就是因为最近要使用Qt,但是由于本人的系统是Ubuntu的,而网上大部分的讲解全是基于Windows的,所以就花费一些时间总结了一下我的安装过程,当然也是也为了能帮助到更多的博友. 第 ...

  3. 使用Python做简单的字符串匹配

    由于需要在半结构化的文本数据中提取一些特定格式的字段.数据辅助挖掘分析工作,以往都是使用Matlab工具进行结构化数据处理的建模,matlab擅长矩阵处理.结构化数据的计算,Python具有与matl ...

  4. centos7安装jdk,tomcat,msyql(MariaDB)

    操作系统版本 CentOS Linux release 7.2.1511 (Core) 安装jdk 下载jdk-8u66-linux-x64.rpm上传到linux上 先改用户权限 然后 rpm -i ...

  5. Windows7 x64 跨平台开发环境安装配置

    ======================================================================= Windows7 x64 跨平台开发环境安装配置 201 ...

  6. 字符串的n位左旋

    要求:将主串的某一段(n位)翻转到主串的最后,如:abcdef以2位翻转则结果为:cdefab.要求时间复杂度为O(n),空间复杂度为O(1) 思路一:可以重新定义一个与原串相同大小的字符数组resu ...

  7. Android项目-高考作文-AsyncTask的不足

    1, AsyncTask的不足. 从android4.0开始, 后台只允许一个AsyncTask执行, 如果当前的AsyncTask没有执行完毕, 那么当前的请求一直处于等待状态. 直到上一个执行完毕 ...

  8. 【一天一道LeetCode】#90. Subsets II

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...

  9. Dynamics CRM EntityCollection 根据实体中的某个字段为依据去除重复数据

    CRM中通过QueryExpression查询出了一个EntityCollection集,但有时会存在重复数据,QueryExpression中有个属性distinct,只要设置为true就能过滤 ...

  10. 类装载器DexClassLoader (android内核剖析)

    在java环境中,有个概念叫做"类装载器",其作用是动态装载Class文件.标准的java SDK中有一个ClassLoader类,借助它可以装载 想要的Class文件,每个Cla ...