1.创建可变数组,和表格
//创建可变数组
var ar:[NSString]=["你是","电脑","得的","爸爸"]
//创建表格
var tab:UITableView?
2.添加
override func viewDidLoad() {
super.viewDidLoad()
//创建表格
self.tab=UITableView(frame: UIScreen.main.bounds, style:.grouped)
self.tab?.delegate=self;
self.tab?.dataSource=self;
//增加视图
view.addSubview(tab!)
}
3.内容
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return ar.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell=tableView.dequeueReusableCell(withIdentifier: "cell")
cell=UITableViewCell(style: .subtitle, reuseIdentifier: "cell")
cell?.textLabel?.text=self.ar[indexPath.row] as String
return cell!
}