UITableView中的单元格重用
来源:互联网 发布:外盘配资端口 编辑:程序博客网 时间:2024/05/18 05:35
UITableView通过重用单元格来达到节省内存的目的:通过为每个单元格指定一个重用标识符(reuseIdentifier),即指定了单元格的种类,以及当单元格滚出屏幕时,允许恢复单元格以便重用.对于不同种类的单元格使用不同的ID,对于简单的表格,一个标识符就够了.
假如一个TableView中有10个单元格,但是屏幕上最多能显示4个,那么实际上iPhone只是为其分配了4个单元格的内存,没有分配10个,当滚动单元格时,屏幕内显示的单元格重复使用这4个内存。
如下代码:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *CellIdentifier =@"CellIdentifier"; UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if(cell==nil){ cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } ***//dequeueReusableCellWithIdentifier:方法查找是否有可以重用的单元格,如果没有则使用initWithStyle:reuseIdentifier:方法构造器创建一个可重用的单元格。*** NSUInteger row=[indexPath row]; NSDictionary *rowDict=[self.listTeams objectAtIndex:row]; cell.textLabel.text=[rowDict objectForKey:@"name"]; NSString *imagePath=[rowDict objectForKey:@"image"]; imagePath=[imagePath stringByAppendingString:@".png"]; cell.imageView.image=[UIImage imageNamed:imagePath]; cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator; return cell;}
注:方法tableView:cellForRowAtIndexPath:是UITableViewDataSourse协议中必须实现的方法之一。
0 0
- UITableView中的单元格重用
- OC-UITableView&UITableViewController&UITableViewCell&单元格重用
- UITableView中的cell重用(原理)以及cell重用解决办法
- UITableView中的cell重用正确,但是重影
- iphone开发之表格组件UITableView的使用(五)UITableView与UItableViewCell常见属性以及单元格重用
- 注册可重用单元格
- UItableView的重用机制
- UITableView的重用机制
- UITableView的重用机制
- UITableView重用机制
- UITableView重用机制
- UITableView重用机制
- UITableView的重用机制
- UITableView的重用机制
- iOS UItableview重用机制
- UITableView的重用机制
- UITableView防止重用
- 浅谈UITableView重用机制
- MyBatis Review——开发Dao的方法
- Canvas文字渲染
- Unity3D学习笔记(10)—— 游戏序列化
- 基于thinkphp3.2使用uploadify单图片上传
- 基于netty的网络聊天室(二)——心跳检测及断线重连
- UITableView中的单元格重用
- socket属性设置
- QQ亿级日活跃业务后台核心技术揭秘
- WindowFrom之ListBox用法
- git rebase
- mysql timeStamp默认值0000-00-00 00:00:00 报错
- XMG CAAnimationGroup动画组
- 树控件
- 计时函数