关于UITableViewCell的重用
来源:互联网 发布:网络上jr是什么意思 编辑:程序博客网 时间:2024/05/21 17:51
整理印象笔记之UITableViewCell的重用
第一种:
- (UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath { //注册重用标识 static NSString *cellID = @"cell"; //缓存池查找可循环的cell UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID]; //没有则初始化(代码自定义的cell) if (cell == nil) { cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID]; } //如果是xib自定义的cell /* TTCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID]; if(cell == nil){ cell = [[[NSBundle mainBundle]loadNibNamed:NSStringFromClass([TTCell class]) owner:nil options:nil] lastObject]; } */ cell.textLabel.text = @"waaa"; return cell;}
第二种:
//定义一个全局变量static NSString *cellID = @"cell";- (void)viewDidLoad { [super viewDidLoad]; //注册标识对应的cell类型(代码自定义cell执行这里) [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:cellID]; //如果是xib自定义的cell需要注册nib文件 [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([TTCell class]) bundle:nil] forCellReuseIdentifier:cellID];}- (UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath { //设置重用cell UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID]; cell.textLabel.text = @"tableViewCell"; return cell;}
第三种:
在storyboard中设置tableView的Dynamic Prototypes Cell
设置cell的重用标识
- (UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath { //注册重用标识 static NSString *cellID = @"cell"; //缓存池查找可循环的cell UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID]; cell.textLabel.text = @"tableViewCell"; return cell;}
阅读全文
0 0
- 关于UITableViewCell的重用
- 关于UITableViewCell的重用初探
- 关于 UITableViewCell 的重用,需注意:
- iOS关于UITableViewCell的重用机制
- UITableViewCell 的重用解决
- UITableViewCell的重用问题
- UITableViewCell的重用
- UITableViewCell的重用
- UITableViewCell的重用原理
- UITableViewCell的重用问题
- UItableViewCell 的重用机制
- UITableViewCell的重用代码
- UITableviewCell的重用机制
- 解析UITableViewCell的重用
- 关于有控件变化的UITableViewCell的重用问题
- iOS-UITableviewCell的重用机制
- iOS-UITableviewCell的重用机制
- UITableViewCell对象的重用原理
- 最近碰到了关于vue-router传值的问题
- Adb采集数据说明书
- php报错 syntax error: unexpected end of file
- [paper]Efficient Deep Learning for Stereo Matching(未完成)
- vue的解构
- 关于UITableViewCell的重用
- mui写web项目,获取当前地理位置
- 《AV Foundation 开发秘籍》读书笔记(二)
- javascript计算对象的长度
- 机器学习技法-01-5-Reasons behind Large-Margin Hyperplane
- 双精度,单精度和半精度
- 前后端分离实践(一)
- 例 5.9 输入一个大于3的整数n,判定它是否为素数(prime,又称质数)。
- 数据集划分函数 train_test_split()