class ViewController: UITableViewDataSource , UITableViewDelegate{}
// tạo mảng , khai bao table , dat id cho cell
var mang:[String]!
@IBOutlet weak var tableDanhSach: UITableView!
// trong ham khoi tao
override func viewDidLoad() {
super.viewDidLoad()
mang = ["Nhut", "Nam", "Tuan"]
tableDanhSach.dataSource = self
tableDanhSach.delegate = self
}
// them 2 hàm
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 3 ;
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell")
cell?.textLabel?.text = "Nhut"
return cell!
}
Không có nhận xét nào:
Đăng nhận xét