UITableView-(单元格的自定义方法)
2024-09-23 15:23:48
//contentView
//行内容
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//从重用队列中取出闲置单元格
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
//判断cell是否为nil
if (cell == nil) {
//创建单元格的时候,要确保重用标示符跟获取闲置单元格的时候一致
cell = [[UITableViewCell alloc] initWithStyle:indexPath.row % reuseIdentifier:identifier];
//添加右边的图标
UIImageView *iconView = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectGetWidth(tableView.frame) - - , , , )];
[cell.contentView addSubview:iconView];
iconView.tag = ; //添加左边的标题Label
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(, , CGRectGetWidth(cell.frame) - , )];
[cell.contentView addSubview:titleLabel];
titleLabel.tag = ;
} UIImageView *iconView = [cell.contentView viewWithTag:];
UILabel *titleLabel = [cell.contentView viewWithTag:]; //设置内容
NSString *iconName = [NSString stringWithFormat:@"icon%ld.jpg",indexPath.row % ];
iconView.image = [UIImage imageNamed:iconName]; titleLabel.text = self.datas[indexPath.row]; return cell; }
最新文章
- 1260: [CQOI2007]涂色paint
- php/js获取客户端mac地址的实现代码
- FAQ: Machine Learning: What and How
- Android实现SharePreferences和AutoCompletedTextView
- java 开发环境
- java vm args
- CF 208E. Blood Cousins [dsu on tree 倍增]
- EtherChannel(PAgP、LACP)基本配置--端口聚合--(转)
- Linux环境——MySQL安装及配置(5.7版本)
- JavaScript实现input输入框限制输入值的功能
- List遍历三种方法:1.for 2.增强性for 3.迭代器
- Head First Servlets &; JSP 学习笔记 第二章 —— Web应用体系结构
- ovs flow 原理及实验
- 第1阶段冲刺成果—简单运算game(APP)
- Linux 下用 smartd 监测硬盘状况
- Openerp 7.0消息推送
- Spring Tool Suite 配置和使用
- PHP Ajax跨域解决
- nvidia tk1使用记录--基本环境搭建
- pandas数据结构和介绍第一天
热门文章
- cocos代码研究(19)Widget子类ImageView学习笔记
- nginx自动生成缩略图
- 前端面试题之 sum(2)(3) (链式调用,toString,柯里化,数组操作)
- ESXi上的固态硬盘识别为非SSD
- rm删除某个文件之外的文件
- POJ 1185 炮兵阵地(状压DP)题解
- 嵌入式Linux应用程序开发环境搭建记录
- Python学习札记(三十一) 面向对象编程 Object Oriented Program 2
- C# .NET 开发心得
- 【源码学习之spark core 1.6.1 standalone模式下的作业提交】