今天在学习IAP的时候无意间看到原来  tableView: cellForRowAtIndexPath:方法中有两个获得重用cell的方法,一直以来都是用
UITableViewCell  *cell  =  [tableView  dequeueReusableCellWithI dentifier:CellIdentifier];那下面的这个怎么用呢,感觉比较怪,假设没有重用的岂不是为空了
UITableViewCell  *cell  =  [tableView  dequeueReusableCellWithI dentifier:CellIdentifier  forIndexPath:indexPath]
具体有什么区别呢,并且当我用  UITableViewCell  *cell  =  [tableView  dequeueReusableCellWithI dentifier:CellIdentifier  forIndexPath:indexPath]的时候,为什么总报错
reason: 
'unable 
to 
dequeue 

cell 
with 
identifier 
Cell 

must 
register 

nib 
or 

class 
for 
the 
identifier 
or 
connect 

prototype 
cell 
in 

storyboard',经过查阅,知道原来此方法为6.0新加的,在SDK5.0是运行不起来的。
 
如果需要使用这个方法,你必须使用配套的方法来一起用,下面两个配套方法选其一:
- (void)registerNib:(UINib *)nib forCellReuseIdentifier:(NSString *)identifier NS_AVAILABLE_IOS(5_0); 

- (void)registerClass:(Class)cellClass forCellReuseIdentifier:(NSString *)identifier NS_AVAILABLE_IOS(6_0);


比如你已经用NIB做了一个Cell,或者自定义了一个Cell。我们在你创建UITableView的时候,就可以顺带

self.tableView.backgroundColor = xxxx; 
[self.tableView registerClass:[CustomCell class] forCellReuseIdentifier:@"CustomCell"];

这样你在


(UITableViewCell 
*)tableView:(UITableView 
*)tableView 
cellForRowAtIndexPath:(NSIndexPath 
*)indexPath这个方法里,
你就可以省下这些代码:

    static NSString *CellIdentifier = @"Cell"; 
 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
 if (cell == nil) {         
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
reuseIdentifier:CellIdentifier];       
//设置你的cell 

而只需要

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
//设置你的cell 
整体来说6.0却是比5.0更省劲

tableview的两个重用cell方法的更多相关文章

  1. iOS - UITableView中有两种重用Cell的方法

    UITableView中有两种重用Cell的方法: - (id)dequeueReusableCellWithIdentifier:(NSString *)identifier; - (id)dequ ...

  2. 关于collectionView和tableView的两种cell的出列方法的区别

    相信好多人一定会对collectionView和tableView的两种cell出列方法有所疑问,下面以UICollection为例子进行举例说明 假设我们已经创建了一个collectionView, ...

  3. iOS学习——UITableViewCell两种重用方法的区别

    今天在开发过程中用到了UITableView,在对cell进行设置的时候,我发现对UITableViewCell的重用设置的方法有如下两种,刚开始我也不太清楚这两种之间有什么区别.直到我在使用方法二进 ...

  4. [How to]使用自定义cell进行tableview的创建,适用于cell样式不发生变化的情况。

    1.简介 在tableview中又默认的cell格式,其中组织如下: <截取自官网文档> 最终的在页面上默认的cell也只能像上述那样的显示效果,如果这种要是无法满足我们的界面要求,那么我 ...

  5. 【iOS开发-58】tableView初识:5个重要方法的使用和2种样式的差别

    创建一个tableView,直接拖拽放在storyboard里面就可以. (1)先创建一个数据模型类WSCarGroup,在WSCarGroup.h文件里: #import <Foundatio ...

  6. [总结]可重用cell的定义方式

    1.简介 为了提高tableview中cell的加载速度通常可以使用cell重用的方式来实现,即我们向上拖动cell的时候,上部份消失的cell可以重复的被下部分出现的cell重用. 2.说明 一般c ...

  7. Set集合对象比较两个元素的方法

    Set集合对象比较两个元素的方法并不是根据“equals()”方法的返回值来比较.而是用“hashCode()”方法来进行判断.只要两个元素的“hashCode()”方法的返回值相同,就认为两个元素相 ...

  8. Java中取小数点后两位(四种方法)

    摘自http://irobot.iteye.com/blog/285537 Java中取小数点后两位(四种方法)   一 Long是长整型,怎么有小数,是double吧     java.text.D ...

  9. JS合并两个数组的方法

    JS合并两个数组的方法 我们在项目过程中,有时候会遇到需要将两个数组合并成为一个的情况.比如: var a = [1,2,3]; var b = [4,5,6]; 有两个数组a.b,需求是将两个数组合 ...

随机推荐

  1. ESXI 5.5卡在LSI_MR3.V00

    方法一 故障现象 此问题无论使用VMware官方镜像还是HP的自定义镜像都会出现一下情况并卡着不动.(此文档普遍存在各种服务器上,包括其它厂商服务器) 故障原因: 故障原因VMware官方和HP官方并 ...

  2. web.xml2.3配置需要注意的顺序问题

    今天在做一个街道办事处项目时,用了eWebeditor编辑器,在按照说明文件进行web.xml配置时,在<web-app>一行上出现红叉,提示信息为:The content of elem ...

  3. 24.最优布线问题(kruskal算法)

    时间限制: 1 s 空间限制: 128000 KB 题目等级 : 白银 Silver 题解 查看运行结果 题目描述 Description 学校需要将n台计算机连接起来,不同的2台计算机之间的连接费用 ...

  4. [转]Android:异步处理之AsyncTask的应用(二)

    2014-11-07     既然UI老人家都这么忙了,我们这些开发者肯定不能不识趣的去添乱阻塞UI线程什么的,否则UI界面万一停止响应了呢——这不是招骂的节奏么?!所以我们知道用Handler+Th ...

  5. mysql中日期比较大小的方法

    假如有个表product有个字段add_time,它的数据类型为datetime,有人可能会这样写sql: select * from product where add_time = '2013-0 ...

  6. iOS开发读取plist文件、iphone中plist文件的

    在Xcode中建立一个iOS项目后,会自己产生一个.plist文件,点击时会看见它显示的是类似于excel表格: 但是,如果打开方式选择Source Code,你会看见它其实是一个xml文件. 我们会 ...

  7. ios开发中object-c中UTF-8 和 GBK 的 NSString 相互转化的方法

    应用都要遇到一个很头疼的问题:文字编码,汉字的 GBK 和 国际通用的 UTF-8 的互相转化稍一不慎, 就会满屏乱码.下面介绍 UTF-8 和 GBK 的 NSString 相互转化的方法   NS ...

  8. mysql 监控工具

    zabbix和grafana是绝配.  pmm的prometheus太占资源了

  9. Curvilinear structure detections

    此部分参考处 As a structure-based detector, PCBR does not use edges, instead, it uses curvilinear structur ...

  10. java自动识别上传的apk版本号

    import java.util.List; public class ApkInfo { private String versionCode; private String versionName ...