override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
<#code#>
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
<#code#>
}
- 사실 이 두가지 메서드는 TableViewController.swift를 생성하면 자동으로 입력되어 있는 것이기도 하다.
// 옵션이지만 지정하는 것이 좋음
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return indexPath.row == 0 ? 44 : 80
//return indexPath.section == 0 ? 44 : 80
}
: 디폴트 값은 1로, 지정해 주지 않으면 하나의 섹션이 만들어 진다.
override func numberOfSections(in tableView: UITableView) -> Int {
return 2
}
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return "섹션 타이틀"
}
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
list.remove(at: indexPath.row)
tableView.reloadData()
}
}