以下是近期总结的关于tableView的一些属性和代理方法,以及一些常见的问题,现汇总如下,今后还会持续更新,请继续关注:
 
tableView 的头部和尾部视图属性:
    UISwitch *footerView = [UISwitch new];
UISwitch *headerView = [UISwitch new];
self.tableView.tableHeaderView = headerView;
self.tableView.tableFooterView = footerView;
注意:不能给tableHeaderView和tableFooterView设置同一个UIView。否则只有headerView没有footerView。
 
返回指定 section 的头部和尾部视图:
// 这是tableView的代理方法
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
// 可以返回指定section的尾部视图
} - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
// 可以返回指定section的头部视图
}
section 的头部和尾部高度属性:
sectionFooterHeight和 sectionHeaderHeight为组头和组尾高度,默认都为10.(已经验证过)
    self.tableView.sectionFooterHeight = ;
self.tableView.sectionHeaderHeight = ;
返回指定 section 的头部和尾部高度:
 
  // 注意:用代理方法设置头部、尾部高度的优先级比通过属性设置要高
  // 即,代理设置的section头部或者尾部的高度会覆盖掉用属性设置的高度
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{ } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{ }
tableView的行高属性:
// 这个属性可以设置所有的行高,通过这个属性设置的行高都一样
self.tableView.rowHeight = ;
返回指定行的高度:
// 优先级比tableView的rowHeight属性要高
// 这是tableView的代理方法
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{ }
问题:如何让tableView的头部标题具有悬停效果?
第一种情况:UIViewController里面添加一个UITableView控件的情况下。
     此时需要设置tableView的style为plain样式。然后再数据源方法- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView中返回tableView的section个数。
     如果tableView的style为grouped样式,则没有悬停效果,即使是分组样式的!
 
第二种情况:UITableViewController自带的UITableView控件的情况下。
     和第一种情况一样,也需要设置tableView的style为plain样式。否则没有头部标题悬停效果。
 
报错:
 reason: 'unable to dequeue a cell with identifier cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
 
原因之一:
UITableViewCell *ce = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
 
报错:
Failed to instantiate the default view controller for UIMainStoryboardFile 'Main' - perhaps the designated entry point is not set?
原因:
没有指定initial View Controller
 
开发技巧:plain单组样式下,如何避免多余的那些没有显示数据的celly依旧显示在屏幕上?
解决方法一:设置tableView的style为grouped并且numberOfSection = 1
解决方法二:给tableView设置tableFooterView = [[UIView alloc] init];
 
cell优先级问题:
注意点:注册cell类型比storyBoard中绑定的cell优先级高,所以如果注册了cell的类型,那么就不会去storyBoard中找绑定的cell。
 
注册xib的cell类he和注册的代码的cell类和比if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];方式创建的cell优先级都高。
 
换言之,注册的要比代码的优先级高(已验证),即: 
[self.tableView registerNib:[UINib nibWithNibName:@"WSCell" bundle:nil] forCellReuseIdentifier:cellID]; 和
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:cellID]; 的优先级 >
if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
 }
至于注册xib和注册非xib的cell,哪个优先级高,这就不确定了!
我验证的结果是:需要看他们的注册顺序,也就是代码顺序。后注册的那一个类型的cell优先级高,我认为是后者把前者覆盖(因为他们的reuseIdentifier相同,所以只允许注册一个)。如下注册了两个类型的cell,但是因为reuseIdentifier相同,所以只有最后一个生效,也就是红色的生效。
 

[self.tableView registerNib:[UINib nibWithNibName:@"WSCell" bundle:nil] forCellReuseIdentifier:cellID];

[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:cellID];
总之记住一句话:不管是系统自带的cell还是纯代码自定义的cell还是xib自定义的cell,只要是注册的cell类,就比if(!cell){...}的优先级高!

UITableView的常用属性和代理方法的更多相关文章

  1. UITableView的常用属性和cell的内存优化

    UITableView的常用属性: 分割线颜色设置: 1> 设置separatorStyle: 分割线的颜色 方法:tableView.separatorStyle = UITableViewC ...

  2. ios开发UI篇—UIScrollView属性及其代理方法

    一.UIScrollView是什么? 1.UIScrollView是滚动的view,UIView本身不能滚动,子类UIScrollview拓展了滚动方面的功能. 2.UIScrollView是所有滚动 ...

  3. UITableView的一些常用设置和代理方法

    - (void)viewDidLoad { [super viewDidLoad]; tableview = [[UITableView alloc]initWithFrame:CGRectMake( ...

  4. 12-27 UITableView常用属性及方法

    UITableView也有自己的代理协议,它本身继承自UIScrollView 一:代理要遵守代理协议<UITableViewDelegate>,代理协议中的代理方法: 1.改变某一行的行 ...

  5. UITableView常用属性和方法 - 永不退缩的小白菜

    UITableView常用属性和方法 - 永不退缩的小白菜 时间 2014-05-27 01:21:00  博客园精华区原文  http://www.cnblogs.com/zhaofucheng11 ...

  6. UITableView的全部属性、方法以及代理方法执行顺序,看过之后肯定有收获---董鑫

    UITableView-------表视图--继承UIScrollView并遵守NSCoding协议 属性 frame-------------设置控件的位置和大小 backgroundColor-- ...

  7. UITableView表格视图、UITableView代理方法及应用

    一.基本知识点 UITableView表格视图,是一个可以滚动的界面(理解为垂直滚动的UIScrollView),可展示多行数据,没有行数的限制,只能有一列. 使用UITableView: 1.展示信 ...

  8. CoreAnimation 核心动画一 (一些常用属性 和 方法)

    1.常用属性: frame   bounds   center   alpha    Transition 过渡    transform 动画效果 2.常用方法: +(void)setAnimati ...

  9. UICollectionView的简单使用和常用代理方法

    UICollectionView相对于UITableView有更加自由的布局,做出的界面可变性更大最近开始接触使用UICollectionView,整理了一下常用的代理方法 首先需要先添加UIColl ...

随机推荐

  1. [bzoj3289]Mato的文件管理

    Description Mato同学从各路神犇以各种方式(你们懂的)收集了许多资料,这些资料一共有n份,每份有一个大小和一个编号.为了防止他人偷拷,这些资料都是加密过的,只能用Mato自己写的程序才能 ...

  2. bzoj2548[Cstc2002]灭鼠行动

    Description 最近,有一些繁殖力很强的老鼠在下水道非常猖獗,灭鼠特工队正在计划消灭这些老鼠.下水道只有东西方向和南北方向的管道,如图所示. 灭鼠特工队的队员拥有强大的武器.他们将在某些时刻t ...

  3. tshark过滤并保存包特定字段

    1.过滤端口为5001的tcp包,将时间输出 tshark -r h1.pcap -Y "tcp.port==5001" -T fields -e frame.time 时间格式如 ...

  4. Java daemon thread 守护线程

    守护线程与普通线程写法上基本么啥区别,在启动线程前, 调用线程对象的方法setDaemon(true),则可以将其设置为守护线程. 守护线程使用的情况较少,但并非无用,举例来说,JVM的垃圾回收.内存 ...

  5. SQL Server 2005、2008 的 datetime 值范围(转)

    SQL Server 2005.2008 的 datetime 最小值是:1753-01-01 00:00:00 最大值是:9999-12-31 23:59:59.997 这与 .NET 中的 Dat ...

  6. [java]java语言初探 servlet+jsp架构

    <<head first java>> https://www.tutorialspoint.com/jsp/jsp_architecture.htm JSP Processi ...

  7. Unity 使用快速教程

    Unity是微软在CodePlex上的一个开源项目,可用于依赖注入.控制反转,类似Spring,下面是使用示例: 1.先来定义几个接口.类 namespace UnityTest { public i ...

  8. 0 bug 读后感

    本书全名是 <0 bug- C/C++商用工程之道>,这是一本有争议的书,豆瓣链接: http://book.douban.com/subject/4149139/ ,建议有一些商用的开发 ...

  9. 【分布式协调器】Paxos的工程实现-Cocklebur状态转移

    集群中的主机经过选举过程由Looking状态变为了Leadering或Following状态.而这些状态之间转移的条件是什么呢?先来个直观的,上状态图. 图 4.1 Cocklebur选举过程中的状态 ...

  10. React Native 在现有项目中的探路

    移动开发中,native开发性能和效果上无疑是最好的. 但是在众多的情况下,native开发并不是最优的选择.当需求经常改动的时候,当预算有限的时候,当deadline很近的时候,native开发的成 ...