UItableveiw的一些使用
来源:互联网 发布:苏亚雷斯巴萨数据 编辑:程序博客网 时间:2024/05/16 02:18
UItableview是iOS用来展示数据的一种重要控件,几乎所有的数据展示页面都可以用UItableView来做
UItableview使用首先要定义声明,可用代码定义也可用storybord直接拖,要设置代理和数据源
代理模式是iOS开发中的重要模式,很好的使用代理可以让代码写起来更省力,有些代理的使用也可以用swift中的闭包或object-c中的block来替代,之后我会上一个代理的例子
tv.delegate = self;
tv.dataSource = self;tableView使用时一定要明白其中的每个代理方法:
常用的代理方法有
定义section数量:
func numberOfSections(in tableView: UITableView) -> Int { return 1 }定义row数量
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return 10 }定义cell
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "ServerCell") as! ServerCell //自定义tableviewcell 复用return cell}
如果不需要自定义cell,也可用系统提供的4种cell
let cell = UITableViewCell(style: .value1, reuseIdentifier: "cel")
4种cell有
public enum UITableViewCellStyle : Int { case `default` // Simple cell with text label and optional image view (behavior of UITableViewCell in iPhoneOS 2.x) case value1 // Left aligned label on left and right aligned label on right with blue text (Used in Settings) case value2 // Right aligned label on left with blue text and left aligned label on right (Used in Phone/Contacts) case subtitle // Left aligned label on top and left aligned label on bottom with gray text (Used in iPod).}
每行的行高:
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { return 10 }
一些常用代码:
UItableViewCell加箭头:cell.accessoryType = .disclosureIndicator
去除系统的分割线:
tv.separatorStyle = .none
tableViewCell 的选中效果:
cell.selectionStyle = .none
如果希望tableview刷新的时候有动画效果
刷新动画// let xx : NSIndexSet = NSIndexSet(index: section)// self.tableveiw.reloadSections(xx as IndexSet, with:.top)
1 0
- UItableveiw的一些使用
- UITableVeiw空白的Cell设置空
- datagrid的一些使用
- PowerDesigner的一些使用
- 触发器的一些使用
- 一些使用的命令行
- SHBrowseForFolder 的一些使用
- ubuntu的一些使用
- find的一些使用
- virsh的一些使用
- tortoiseSVN的一些使用
- StringUtils的一些使用
- #pragma的一些使用
- myeclipse的一些使用
- qwt 的一些使用
- 宏的一些使用
- git 的一些使用
- js的一些使用
- SelectSort 选择排序
- centos 7配置ip地址
- OpenCV_(HougLines transform)霍夫变换检测直线
- 基础算法——快速排序
- Android 自定义View学习之文字绘制
- UItableveiw的一些使用
- Linux系统内核分析实验——system_call中断处理过程
- JAVA HttpURLConnection Post方式提交传递参数
- css3实现的手风琴效果
- GYM 101102 C.Bored Judge(map)
- Struts2配置RESULT中TYPE的参数说明
- 给定两个排序的数组,其中A有足够空间容纳B,实现一个方法将B容纳进A并排序
- Codeforces Round #404 (Div. 2) A. Anton and Polyhedrons
- eclipse中安装svn插件