【UIKit】UITableView 3
UITableView 代码
【1】拖入一个UITableView
【2】将TableView的dataSource与控制器连接
【3】首先得遵循UITableView的数据源协议<UITableViewDataSource>
【4】加入图标文件
【5】代码
1.设置一共多少组,系统默认是1组,所以不写的话就默认1组
#pragma mark 返回多少组 -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {// 在这里默认是1,写与不写一样return 1; }
2.返回多少行,这里返回9行
#pragma mark 返回一组多少行 -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {return 9; }
3.返回每一行的具体数据
下表为箭头样式
UITableViewCellAccessoryCheckmark |
|
UITableViewCellAccessoryDetailButton |
|
UITableViewCellAccessoryDetailDisclosureButton |
|
UITableViewCellAccessoryDisclosureIndicator |
|
UITableViewCellAccessoryNone |
表示没有 |
#pragma mark 返回具体数据 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitlereuseIdentifier:nil];/************************设置左边图标*******************/// 1.取出第i行所使用的图片名称NSString *imageName=[NSString stringWithFormat:@"00%d.png",indexPath.row+1];// 2.cell.imageView.image=上面取得的image的名字cell.imageView.image=[UIImage imageNamed:imageName];/***********************设置主标题*********************/cell.textLabel.text=@"12312432";// 设置子标题,需要在上面的UITableViewCellStyleDefault改为UITableViewCellStyleSubtitlecell.detailTextLabel.text=@"详细描述"; //子标题内容为详细描述// 设置cell箭头样式cell.accessoryType=UITableViewCellAccessoryCheckmark;return cell;}
4.设置每一行的行高
1)加入代理
2)添加代理协议<UITableViewDelegate>
3)调整高度
#pragma mark- 调整每一行的高度,代理方法 -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {// 设置所有高度为70;return 60;// 也可以根据传入的不同内容进行不同的高度设置// 行数越多,高度越高//return 40+indexPath.row*5; }
转载于:https://www.cnblogs.com/madeininfi/p/3667495.html
【UIKit】UITableView 3相关推荐
- 【UIKit】UITableView 自定义Cell2
[自定义Cell2][Code]:全部通过代码添加 [1]:设置Cell 1):创建一个MsgCell类 继承UITableViewCell .h中声明2个属性一个是用户头像,另外一个是发表的文字 ...
- 【UIKit】UITableView 1
UITableView:代码 section:组别 row:行号 [1]拖入一个UITableView [2]将TableView的dataSource与控制器连接 [3]首先得遵循UITableV ...
- 【UIKit】UITableView.02
UITableView.02: [1]拖入一个UITableView [2]将TableView的dataSource与控制器连接 [3]首先得遵循UITableView的数据源协议<UITab ...
- 【UIKit】UITableView.06
UITableView.06: [1]拖入ToolBar,TableView [2]连线,设置代理模式,数据源等(ToolBar中的垃圾桶也需要连接方法removeRow) [3]代码 1.声明 my ...
- 【UIKit】表格 UITableView
UITableView的使用介绍 官方文档:Table View Programming Guide for iOS UITableView基本使用基本步骤 准备数据源的数组 遵循的协议UITable ...
- 【UIKit】表格自定义单元格(UITableViewCll)
自定义表格单元格(Cell)操作 使用NIb文件自定义单元格(Cell) 1. 创建UITableViewCell的子类,创建的同时记得选择生成xib文件(当然你也可以将控件通过代码 ...
- 【UIKit】UIView基础学习
UIView基础介绍 官网文档: View programming Guide for iOS UIView Class Reference [常用属性和方法] UIKit User Interfac ...
- 【UIKit】文本框(UITextField)及键盘遮挡处理和回收
文本框(UITextField)及键盘遮挡处理和回收 文本框属性 官网文档:UITextField Class Reference 以下都是可以在IB中选择设置的,也可以使用代码编写 placehol ...
- 【UIKit】TabView
[TabView] [下面的tab栏][code] [第一步]:创建一个Tabbed Application [第二步]:加入图片素材. [第三步]:创建3个有xib的类文件 FirstViewCo ...
最新文章
- SQLite数据库存储
- 学生档案管理系统(续)
- boost::units模块实现测试数量之间的转换的测试程序
- 高级数据结构与算法 | AVL树 (高度平衡树)
- python 免费空间_总算找到php免费空间
- 电子计算机技能竞赛数据,2015年浙江省中等职业学校计算机应用技术专业学生职业技能大赛“计算机检测维修与数据恢复”赛项规程.doc...
- width:100vh与min-height:calc(100vh + 51px)
- 将 nginx 安装成 windows 的方法
- PHP判断用户是否登录
- python项目开发实例-Python小项目:快速开发出一个简单的学生管理系统
- java---数组常用的方法:
- 如何用科研经费报销会务、餐饮、住宿费
- 常见的SQL面试题:经典50例
- PDF转换成word转换器绿色版使用步骤
- 短视频去水印威信小程序源码下载,内附去水印解析接口
- react 跨域—— jsonp 跨域
- android10.0连接wifi后提示“已连接,但无法访问互联网”
- Scout - 可扩展的服务器和应用监控服务
- FI--SAP财务系统总账应用技巧
- 安卓手机通过USB连接路由器有线上网