cell 重用
1. 当单元格因滚屏而脱落表格可见区时,表格可以将其缓存到重用队列中。
用法:我们可标记单元格以备重用,然后根据需要从该队列中提取。
在分配新单元格时,必须检查重用单元格是否可用。如果表格对dequeueReusableCellWithIndentifier:的请求返回nil,那么就需 要分配一个新的单元格。
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
我们一般会改成
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier ];
if (!cell) {
UITableViewCell *cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:CellIdentifier];
}
2.如果用默认的方法则需要用下面两个方法的任意一个
- (void)registerNib:(UINib *)nib forCellReuseIdentifier:(NSString *)identifier ;
- (void)registerClass:(Class)cellClass forCellReuseIdentifier:(NSString *)identifier ;
先注册一个
[self.tableView registerClass:[CustomCell Class] forCellReuseIdentifier:@"CustomCell"];
而只需要 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
cell 重用的更多相关文章
- iOS - UITableView中Cell重用机制导致Cell内容出错的解决办法
"UITableView" iOS开发中重量级的控件之一;在日常开发中我们大多数会选择自定Cell来满足自己开发中的需求, 但是有些时候Cell也是可以不自定义的(比如某一个简单的 ...
- 解决UITableView中Cell重用机制导致内容出错的方法总结
UITableView继承自UIScrollview,是苹果为我们封装好的一个基于scroll的控件.上面主要是一个个的 UITableViewCell,可以让UITableViewCell响应一些点 ...
- 解决Cell重用内容混乱的几种简单方法,有些方法会增加内存
重用实现分析 查看UITableView头文件,会找到NSMutableArray* visiableCells,和NSMutableDictnery* reusableTableCells两个结构 ...
- iOS解决cell重用问题
在写sina 微博界面的过程中使用到了cell,那么就是在cell上添加一些控件,但是由于每条微博的内容都是不同的,所以在显示的过程中,出现了内容重叠的问题,其实就是UITableViewCell重用 ...
- 解决Cell重用问题
在显示的过程中,出现了内容重叠的问题,其实就是UITableViewCell重用机制的问题. 解决方法一:对在cell中添加的控件设置tag的方法 在cell的contentView上需要添加控件,那 ...
- UITableViewCell在非Nib及Cell重用下设置CellStyle
在UITableViewController(实现了UITableViewDataSource)下需要实现 - (UITableViewCell *)tableView:(UITableView *) ...
- ios UITableView中Cell重用机制导致内容重复解决方法
UITableView继承自UIScrollview,是苹果为我们封装好的一个基于scroll的控件.上面主要是一个个的 UITableViewCell,可以让UITableViewCell响应一些点 ...
- cell重用的几种方式
1.使用xib重用 //ios6 之后推荐大家使用的重用方式 //动态的使用self获得当前类名,来作为唯一的标示 NSString * identifier = NSStringFromClass( ...
- UI:UITableView 编辑、cell重用机制
tableView编辑.tableView移动.UITableViewController tableView的编辑:cell的添加.删除. 使⽤场景: 删除⼀个下载好的视频,删除联系⼈: 插⼊⼀条新 ...
- IOS Cell重用机制
重用机制: -(UITableViewCell *)tableView: (UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *) ...
随机推荐
- conda
Conda是什么? Conda 是Anaconda下用于包管理和环境管理的命令行工具, Conda下一切都是包,包括Python和conda自己 Conda ≍ pip(包管理) + vitualen ...
- [WorldWind学习]19.WebDownload
using System; using System.Diagnostics; using System.Globalization; using System.Net; using System.I ...
- PAT 1044 Shopping in Mars[二分][难]
1044 Shopping in Mars(25 分) Shopping in Mars is quite a different experience. The Mars people pay by ...
- com.sun.image.codec.jpeg在Eclipse中报错的解决办法
在Eclipse中处理图片,需要引入两个包:import com.sun.image.codec.jpeg.JPEGCodec;import com.sun.image.codec.jpeg.JPEG ...
- 在Qt中如何编写插件,加载插件和卸载插件(转)
Qt提供了一个类QPluginLoader来加载静态库和动态库,在Qt中,Qt把动态库和静态库都看成是一个插件,使用QPluginLoader来加载和卸载这些库.由于在开发项目的过程中,要开发一套插件 ...
- AVAudioFoundation(4):音视频录制
本文转自:AVAudioFoundation(4):音视频录制 | www.samirchen.com 本文主要内容来自 AVFoundation Programming Guide. 采集设备的音视 ...
- 【运维技术】shell脚本实现线程挂掉,自动重启功能
由于分布式系统的流行,服务器上面部署的项目都是多实例的.而我又希望有一个功能,当服务器出现异常情况能够自动重启实例. 所以我想到了使用shell脚本监控实例进程id,如果不存在的话,就重启对应的实例. ...
- 20172305 2018-2019-1 《Java软件结构与数据结构》第二周学习总结
20172305 2018-2019-1 <Java软件结构与数据结构>第二周学习总结 教材学习内容总结 本周内容主要为书第三章和第四章的内容: 第三章(以数组来替代栈的作用) 集合(聚集 ...
- android驱动学习---led实验
======================== 驱动: 内核:android-kernel 2.6.36 (必须对应你的板子上内核,不然会出现insmod错误) 目的:通过android应用层用户 ...
- c#pdf查看器
Free Spire.PDF for .NET is a Community Edition of the Spire.PDF for .NET, which is a totally free PD ...