上一篇我们讲到建立一个UItable View的一些基本方法,接下来我们可以建立一些资料在上面
var list = [
("cart", "购物", "安排於9/1"),
("eye", "看眼科", "安排於9/2"),
("bicycle", "骑单车", "安排於9/3"),
("figure.walk", "健走", "安排於9/4"),
]
之後我们把"有几个row",设定成我们list的数量
func tableView( tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return list.count
}
之後把每个row要显示的东西透过cellForRowAt这个功能显示出来
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableview.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell.imageView?.image = UIImage(systemName: list[indexPath.row].0)
cell.textLabel?.text = list[indexPath.row].1
cell.detailTextLabel?.text = list[indexPath.row].2
return cell
}
刚刚设的储存码(Identifier),简单解释就是假设我们有10000笔资料要显示,一次显示10000笔资料会对效能产生很大影响,所以我们就可以使用重用机制,只产生显示於画面上的资料,当使用者滑动时,将画面上的资料更新成下一笔~
然後我们可以藉由下列function去知道哪个表格被我们点选:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print("you tap me!")
}
完成後如下:可以看到终端机上面显示的"you tap me!"
<<: [Day26] 用 Rocket 做一个图书馆门禁後端 (Part 3)
这篇要补充一个比较少使用到的 useLayoutEffect hook,和 useEffect 语法...
找到股价站上 20 周线只是第一步,不是一站上就会开始飙升,我还会搭配价位突破「箱型区间」,这个突破...
今天要来带大家看看TypeScript(TS)的类别(Class)继承(Inheritance)范例...
建立原型要点 根据 Google Glass 案例里提到的经验总结,制作低精度原型目的是为了及早失败...
缘起与目标 第 1 天的 exercise,首先帮自己制定目标,由於接下来刚好是周末,我想要思考一个...