Swift-表格
//1.创建表格
let tv = UITableView(frame: view.bounds, style: .Plain)
//2.添加到视图
view.addSubview(tv)
//3.注册可以使用的cell [UITableViewCell class] OC
tv.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cellID")
//4.设置数据源
//Swift 中没有遵守协议是一个错误
tv.dataSource = self
(遵守协议 UITableViewDataSource)
注:在Swift中没有 @interface ViewController (),因此在 class ViewController: UIViewController , UITableViewDataSource
实现协议方法:
//MARK:UITableViewDataSource
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 20
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cellID")
//提示:textLabel 是可选的
//代码中?是自动带的,如果textLabel有就使用
cell?.textLabel?.text = "hello world ----\(indexPath.row)"
return cell!
}
最新文章
- python之sys模块详解
- 微信 {";errcode";:40029,";errmsg";:";invalid code, hints: [ req_id: Cf.y.a0389s108 ]";}
- shell note
- Listview和Gridview自定义分割线
- C#语言基础02
- bzoj2757
- 我的开发框架(WinForm)3
- (九)groupByKey,reduceByKey,sortByKey算子-Java&;Python版Spark
- cygwin编译SDL1.2
- HDU4127(IDA*)
- NPOI操作类
- [USACO15OPEN]回文的路径Palindromic Paths 2.0版
- JS基础(二)
- Leetcode解题-链表(2.2.6)RotateList
- 记录几个字符串转html的帮助类,已防忘记
- nginx 学习笔记
- JAVA设计模式初探之适配器模式
- css链接link
- 初识MapReduce
- linux源码安装 rpm命令
热门文章
- 2019-RHCE-红帽题库(稳定)
- Go语言资源教程:Redis介绍安装和使用
- 转载黑客是如何黑到你手机的?绝对涨姿势,一位黑客的Wi-Fi入侵实录!
- 云端搭建Linux学习环境 链接https://edu.aliyun.com/article/19 (阿里云ECS服务器 )课堂
- chrome插件-YSlow 一个使用的web性能测试插件
- C++ 标准库智能指针
- the swap trick用于锐减过剩容量
- 浅谈 关于ARC循环引用得问题
- js判断字符串是否有下划线
- javaEE 转发 和 重定向