프로그래밍 방식으로 간단한 TableView 예제를 만들었습니다.didSelectRowAt 메서드가 호출되지 않았습니다. (신속한 3)
import UIKit
class ViewController: UIViewController
{
var solarObjects : UITableView! = nil
var dataSourceTable:DemoTable?
override func viewDidLoad()
{
super.viewDidLoad()
solarObjects = UITableView(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height * 0.9))
solarObjects.allowsSelection = true
solarObjects.backgroundColor = UIColor.white
self.dataSourceTable = DemoTable()
self.solarObjects.dataSource = self.dataSourceTable
view.addSubview(solarObjects)
}
override func didReceiveMemoryWarning()
{
super.didReceiveMemoryWarning()
}
}
그리고 solarObject에 대한 데이터 소스는 별도의 파일에 (DemoTable.swift)이 샘플은 완벽하게 실행하지만 난 행을 선택할 때 didSelectRowAt 방법은 응답하지 않는
import Foundation
import UIKit
class DemoTable: UITableViewController
{
var arr_SolarObjects = ["SUN", "MOON", "STAR"]
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return arr_SolarObjects.count
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath){
print("A SolarObject is selected")
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
var cell = tableView.dequeueReusableCell(withIdentifier: "Cell")
if cell == nil {
cell = UITableViewCell(style: .default, reuseIdentifier: "Cell")
cell?.frame(forAlignmentRect: CGRect(x: 0, y: 0, width: tableView.frame.size.width, height: 30))
}
cell?.textLabel?.text = arr_SolarObjects[indexPath.row]
return cell!
}
}
-> (인쇄 ("SolarObject가 선택됨")), 행 선택에 대한 작업을 처리하는 방법은 무엇입니까? DemoTable을 : 도움말
self.solarObjects.delegate = self.dataSourceTable
didSelectRow
는 UITableViewDelegate
은 이제 의미가 있습니다. Mhergon에게 감사드립니다. –