Why is -didDeselectRowAtIndexPath not being called?

后端 未结 10 1754
梦如初夏
梦如初夏 2020-11-29 05:38

I created a fresh project (Xcode 4, Master-Detail application) just to see if I\'m doing something wrong, but I still have the same problem. I want to call -reloadData

10条回答
  •  Happy的楠姐
    2020-11-29 06:23

    A clean way of solving this problem is to do the following:

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("myCell", forIndexPath: indexPath)
        // Do your cell setup work here...
    
        //If your cell should be selected...
        if cellShouldBeSelected {
            tableView.selectRowAtIndexPath(indexPath, animated: false, scrollPosition: UITableViewScrollPosition.None)
        }
    
        return cell
    }
    

    This solves this entire problem of a cell not responding to being deselected after a tableView.reloadData()call happens.

提交回复
热议问题