不调用tableView(_ tableView:UITableView,didSelectRowAt indexPath:IndexPath)

swi*_*123 -4 uitableview ios swift

我的结构如下:

UIViewController -> UIVIew -> UITableView

tableView(_ tableView: UITableView, numberOfRowsInSection section: Int)

tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath)

被称为但是

tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)

不叫.

class ViewcontrollerA : UIViewController  , UITableViewDelegate , UITableViewDataSource {

    override func viewDidLoad() {
        super.viewDidLoad()

        self.doctortableView.delegate = self
        self.doctortableView.dataSource = self
        self.doctortableView.allowsSelection = true

    }

    func callTable() {

        doctortableView.frame = CGRect(......)
        view1.addSubview(doctortableView)
        doctortableView.isUserInteractionEnabled = true

        self.view.addSubview(view1)

    }

    // Tableview Functions

    // Number of Sections in Table
    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }


    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

        var count = Int()

        return count
    }


    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

        var cell = UITableViewCell()

        return cell
    }

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

        //This function is not called
    }
}
Run Code Online (Sandbox Code Playgroud)

Jer*_*emy 5

乍一看似乎是这个数据源方法的问题.

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

    var count = Int()

    return count
}
Run Code Online (Sandbox Code Playgroud)

Int()归0?这意味着您的tableview没有任何单元格.