暑期项目开发实训 Day3
来源:互联网 发布:宁夏广播电视网络缴费 编辑:程序博客网 时间:2024/05/22 05:05
今天开始做第2个Demo。内容是一个Checklists。
Checklists是App Store中比较热门的一类应用,仅次于健身App(作者如是说,其实我也不信)。
做Checklists时需要用到TableViewController。主要的设计元素是Table和Navigation。
注意到,采用tableView需要实现数据源协议:
// two data source protocol
// the data source is the link between your data and the table view.
我们重写两个tableView的函数:
// find how many rows there are. override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return 100 // there is only m rows, so return m } // ask the data source for a cell. override func tableView(_ tableView:UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { // indexPath is an obj that points to a specific row in the table. let cell = tableView.dequeueReusableCell( withIdentifier: "ChecklistItem", for: indexPath) let label = cell.viewWithTag(1000) as! UILabel if indexPath.row % 5 == 0 { label.text = "Walk the dog" } else if indexPath.row % 5 == 1 { label.text = "Brush my teeth" } else if indexPath.row % 5 == 2 { label.text = "Learn iOS development" } else if indexPath.row % 5 == 3 { label.text = "Soccer practice" } else if indexPath.row % 5 == 4 { label.text = "Eat ice cream" } return cell // to obtain the cell for that row }
需要注意的是, tableView中 Cell 和 Row的关系。
简单而言,cell是页面中出现的容器, Row是容器中的包含数据的具体内容的。
// ways to create cells in tableView
// 1. add a prototype cell to the table view in the storyboard
// 2. set a reuse identifier on the prototype cell;
// 3. call tableView.dequeReusableCell(withIdentifier);
// You will usually have fewer cells than rows. For run out of memory.
所以我们会发现Cell一般是少于Row的,因为防止内存耗尽。
最后我尝试了tap后让row变成de-selected,以及toggle the checkmarks。
// tap后消失 变成 de-selected 勾选功能 toggle the checkmarks. override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { if let cell = tableView.cellForRow(at: indexPath) { if cell.accessoryType == .none { cell.accessoryType = .checkmark } else { cell.accessoryType = .none } } tableView.deselectRow(at: indexPath, animated: true) }
今天明天早上要考毛概了,所以今天实在无心恋战~ 只完成了一点点工作。
- 暑期项目开发实训 Day3
- 暑期项目开发实训 Day1
- 暑期项目开发实训 Day2
- 暑期项目开发实训 Day4
- 暑期项目开发实训 Day4
- 暑期项目开发实训 Day5
- 暑期项目开发实训 Day6
- 暑期项目开发实训 Day7
- 暑期项目开发实训 Day8
- 暑期项目开发实训 Day9
- 暑期项目开发实训 Day9
- 暑期项目开发实训 Day10
- 暑期项目开发实训 Day11
- 暑期项目开发实训 Day12
- 暑期项目开发实训 Day13
- 暑期项目开发实训 Day14
- 暑期项目开发实训 Day15
- 暑期项目开发实训 Day16
- 【PB】——创建数据库
- Oracle之tnsnames.ora的若干问题
- C++ sort排序的妙用
- struts2拦截器
- git(二)-git添加-删除-修改与日志
- 暑期项目开发实训 Day3
- 1013. 数素数 (20) python 2 编译
- 基于V4L2的视频驱动开发
- CSDN博客初体验
- 第八课 类的封装
- Android消息机制-Handler原理(三)
- 今天聊聊前端之事件
- 微信小程序:发送请求
- Cannot connect to the Docker daemon. Is the docker daemon running on this host?问题解决