本文主要是介绍Xcode9学习笔记40 - 使用UITableView制作简单表格,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
import UIKitclass ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {//表格视图数据源协议、表格视图代理协议override func viewDidLoad() {super.viewDidLoad()// Do any additional setup after loading the view, typically from a nib.let rect = CGRect(x: 0, y: 40, width: 320, height: 420)//创建一个现实区域let tableView = UITableView(frame: rect)//初始化一个表格视图,并设置其位置和尺寸tableView.delegate = self//设置表格视图的代理为当前的视图控制器类tableView.dataSource = self//设置表格视图的数据源为当前的视图控制器类self.view.addSubview(tableView)//将表格视图添加到当前视图控制器的根视图中}//添加一个代理方法,用来设置表格视图y拥有5行单元格func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {return 5}//添加一个代理方法,用来初始化或复用表格视图中的单元格func tableView(_ tableView: UITableView, cellForRowAt indexPath:
这篇关于Xcode9学习笔记40 - 使用UITableView制作简单表格的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!