클래스가 UITableViewController
의 서브 클래스 인 경우, 사용
class ViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell.textLabel?.text = "\(indexPath.row)"
cell.accessoryType = UITableViewCellAccessoryType.detailButton
return cell
}
override func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) {
print(indexPath.row)
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 10
}
}
을 그리고 그것은 UIViewController
의 서브 클래스 인 경우에 당신은 그 방법 전에 override
을 필요가 없습니다 그것이 될 것입니다 :
func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) {
print(indexPath.row)
}
이 경우에는 ViewController
과 함께 테이블 뷰의 UITableViewDataSource
과 UITableViewDelegate
을 연결하는 것을 잊어 버리십시오.
자세한 내용은 example을 확인하십시오.