Swift UITableView didSelectRowAtIndexPath not getting called

前端 未结 10 2136
野的像风
野的像风 2021-02-06 23:18

New to IOS development and am having trouble with handling cell selection on a table. Whenever I select, the method is not getting called below - any idea why?

My proje

10条回答
  •  Happy的楠姐
    2021-02-06 23:54

    You have to set an @IBOutlet to the tableView in you ViewController and set as it's delegate and dataSource to you can see the data an respond to changes in the tableView.

    Something like this :

    override func viewDidLoad() {
        super.viewDidLoad()
    
        self.tableView.delegate = self
        self.tableView.dataSource = self
    }
    

    And implements the UITableViewDataSource protocol too.

    Or you can too in the Interface Builder set the ViewController as it's delegate and dataSource (more easy to do I think) and avoid to set manually in code like above. Is up to you.

    I hope this help you.

提交回复
热议问题