自定义cell的复用方式2
来源:互联网 发布:dota2小刘 知乎 编辑:程序博客网 时间:2024/05/14 08:01
下面我们来一起看一下自定义cell的第二种复用方式,通过注册复用,获取数据参考上一篇微博:
http://blog.csdn.net/lee727n/article/details/72584599
注册复用自定义cell
viewdidload中注册
- (void)viewDidLoad { [super viewDidLoad]; //向 tableView 注册 cell 的样式 如果是 纯代码的自定Cell 使用该方法// [self.tableView registerClass:[ListCell class] forCellReuseIdentifier:@"listcell"]; //向 tableView 注册 cell 的样式 这里需要tableView 根据 xib 帮我创建cell 对象 UINib *listnib = [UINib nibWithNibName:@"ListCell" bundle:nil]; [self.tableView registerNib:listnib forCellReuseIdentifier:@"listcell"]; //通过属性 设置行高 self.tableView.rowHeight = 80;}
实现三问一答
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1;}- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.allLists.count;}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { //复用方式二 ListCell *listCell = [tableView dequeueReusableCellWithIdentifier:@"listcell" forIndexPath:indexPath]; NewsList *newsList = self.allLists[indexPath.row]; listCell.newsTitleLabel.text = newsList.title; listCell.newsCommentCountLabel.text = [NSString stringWithFormat:@"%ld", newsList.commentCount]; listCell.newsImageView.image = [UIImage imageNamed:newsList.newsImage]; return listCell;}
阅读全文
0 0
- 自定义cell的复用方式2
- 自定义cell的复用方式1
- 自定义cell的三种方式
- IOS 自定义Cell的3种方式
- 自定义加载cell 两种靠谱的方式
- 使用Nib自定义Cell的复用
- tableview 自定义cell 点击cell改变cell中的label.text的字体颜色,cell复用出现问题
- tableview 自定义cell 点击cell改变cell中的label.text的字体颜色,cell复用出现问题
- 自定义cell 3中方式
- iOS——自定义cell的两种方式
- UICollectionViewCell中cell的定义与自定义方式总结
- 自定义等高cell和不等高cell的方式对比
- 自定义Cell的用法
- 自定义Cell的线条
- 自定义cell的frame
- 自定义cell的高度
- 自定义cell的用法
- 自定义cell的流程
- 路由器IP访问控制列表的功能及其配置命令
- debian8.8使用rdesktop远程登录win7
- mybatis 思维导图
- 简单使用网页中插入百度地图的方法
- Hadoop+Spark分布式集群搭建过程
- 自定义cell的复用方式2
- 程序员面试题之基数排序
- JavaScript之文本框脚本(表单脚本)
- 剑指offer面试题2:实现Singleton模式
- JavaScript 函数 preventDefault()
- ARM Linux 3.x的设备树(Device Tree)
- Linux 命令-文件管理命令
- 安卓音乐播放器,简单,开源
- javascript的window.ActiveXObject对象,区别浏览器的方法