UITableView delegate and dataSource methods not getting called

后端 未结 8 1380
野性不改
野性不改 2021-02-13 14:23

I have a UIView which contains a UITableView. The tableview\'s delegate is set to my UIView, but it never calls the delegate methods:

-(id)init {
    self = [sup         


        
8条回答
  •  清酒与你
    2021-02-13 15:05

    I accidentally set my tableView's allowsSelection property to false.

    Storyboard solution

    Select your table view and set the following...

    Swift solution

    override func viewDidLoad() {
        super.viewDidLoad()
        tableView.allowsSelection = true
    }
    

    Notes

    1. At first, I thought this was a UITableViewDelegate issue (as other answers suggested). It wasn't. I linked it to my view controller in my storyboard.
    2. Next, I thought it was a UITableViewDataSource issue, in that I didn't implement the protocol's numberOfSections(in tableView:) method (as other answers suggested). It wasn't. According UIKit's documentation,

    // Default is 1 if not implemented

    1. Finally, I checked the settings on my table view :]

提交回复
热议问题