UITableViewCell的循环利用 - 在storyboard里
来源:互联网 发布:淘宝商品详情图做法 编辑:程序博客网 时间:2024/05/19 17:08
#import "TableViewController.h"@interface TableViewController ()@end@implementation TableViewController- (void)viewDidLoad { [super viewDidLoad];}#pragma mark - Table view data source- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ //有20行 return 20;}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ if (indexPath.row % 2 == 0) { // 1.重用标识 //被static修饰的局部变量只会初始化一次,在整个程序运行的过程中只有一份内存 static NSString *ID = @"cell"; // 2.先根据cell的标识去缓存池中查询可以循环利用的cell UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID]; // 3.如果cell为nil,意味着缓存池找不到对应的cell if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID]; } //4.设置cell上显示的数据 cell.textLabel.text = [NSString stringWithFormat:@"test - %zd",indexPath.row]; return cell; }else{ // 1.重用标识 //被static修饰的局部变量只会初始化一次,在整个程序运行的过程中只有一份内存 static NSString *ID = @"cell2"; // 2.先根据cell的标识去缓存池中查询可以循环利用的cell UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID]; // 3.如果cell为nil,意味着缓存池找不到对应的cell if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID]; } //4.设置cell上显示的数据 cell.textLabel.text = [NSString stringWithFormat:@"test - %zd",indexPath.row]; return cell; } }@end最后效果:
0 0
- UITableViewCell的循环利用 - 在storyboard里
- UITableViewCell的循环利用
- storyboard 拖 UITableviewCell的问题
- UITableViewCell的循环利用(CPU使用率的优化)
- iOS 解决在Storyboard中修改UITableViewCell背景色无效果的问题
- IOS-如何在UITableViewCell里进入ViewController
- 在Storyboard里拉伸一张图片
- C++里枚举在循环里的问题
- C语言 scanf在while循环里的无限循环
- storyboard中用xib文件创建定制的UITableViewCell对象
- storyboard中用xib文件创建定制的UITableViewCell对象 .
- storyboard中用xib文件创建定制的UITableViewCell对象
- Autolayout和Storyboard中动态UITableViewCell的高度
- iOS: Autolayout和Storyboard中动态UITableViewCell的高度
- Autolayout和Storyboard中动态UITableViewCell的高度
- 在storyboard里设置VC的 tab bar item 的 selected image 运行tabbar不显示
- swift 自定义控件在StoryBoard(xib)里使用的属性
- 使用xcode在storyboard里设置按钮圆角的方法
- 【slighttpd】基于lighttpd架构的Server项目实战(2)—预备知识之libevent
- Androidx学习笔记(48)--- 创建Activity
- centos 中打字的小键盘不见了
- 【慕课笔记】U3 继承 第2节 JAVA中的方法重写
- JAVA WEB学习路线
- UITableViewCell的循环利用 - 在storyboard里
- 设计模式:策略模式
- HDU1242 rescue 【BFS+优先队列】
- Androidx学习笔记(49)--- Activity的跳转
- Codeforces Round #341 (Div. 2)(A)模拟
- hdu3081 Marriage Match II
- sdk不能更新
- 程序员必知的一些快捷键!
- Codeforces Round #341 (Div. 2)(B)数学