swift|swift 表格
// 屏幕的宽
let SCREEN_WIDTH = UIScreen.main.bounds.size.width
// 屏幕的高
let SCREEN_HEIGHT = UIScreen.main.bounds.size.height
import UIKit
class ViewController: UIViewController,UITableViewDelegate, UITableViewDataSource {
lettableView =UITableView()
【swift|swift 表格】overridefuncviewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = .orange
lettbv =UITableView(frame:self.view.frame, style: .grouped)
tbv.backgroundColor = UIColor.white;
view.addSubview(tbv)
tbv.dataSource=self
tbv.delegate=self
}
// cell的个数
functableView(_tableView:UITableView, numberOfRowsInSection section:Int) ->Int{
return10
}
// UITableViewCell
functableView(_tableView:UITableView, cellForRowAt indexPath:IndexPath) ->UITableViewCell{
letcellid ="testCellID"
varcell = tableView.dequeueReusableCell(withIdentifier:"cellid")
ifcell ==nil{
cell =UITableViewCell(style: .subtitle, reuseIdentifier: cellid)
}
cell?.textLabel?.text="这个是标题~"
returncell!
}
// 设置cell高度
functableView(_tableView:UITableView, heightForRowAt indexPath:IndexPath) ->CGFloat{
return60.0
}
// 选中cell后执行此方法
functableView(_tableView:UITableView, didSelectRowAt indexPath:IndexPath) {
print(indexPath.row)
}
}
推荐阅读
- Swift中willSet和didSet的简述
- 屏幕另一边的纠结
- Hacking|Hacking with iOS: SwiftUI Edition - SnowSeeker 项目(一)
- LeetCode算法题-11.|LeetCode算法题-11. 盛最多水的容器(Swift)
- 1040表格和W-2表格
- iOS-Swift-map|iOS-Swift-map filter reduce、函数式编程
- Swift|Swift ----viewController 中addChildViewController
- SwiftUI|SwiftUI iOS 瀑布流组件之仿CollectionView不规则图文混合(教程含源码)
- Swift高级应用|Swift高级应用 -01
- Swift5.0|Swift5.0 UITexview的基本使用