DidDeselectRowAtIndexPath indexPath nil

I have a TableViewController that implements the methods of TableViewDelegate:

public override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    let cell = tableView.cellForRowAtIndexPath(indexPath) as! ParticipantesSearchTableViewCell
    cell.viewModel?.active = true
}

public override func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {
    let cell = tableView.cellForRowAtIndexPath(indexPath) as! ParticipantesSearchTableViewCell
    cell.selectedStateImageView.hidden = true
    cell.viewModel?.active = false
}

Note that I never delete or set tableView.editing to true. In addition, my method numberOfRowsInSectionnever changes.

If I set my tableView to tableView.allowsSingleSelection = true, I can select and deselect cells only in order, and the above methods will be treated as aspected. However, when I look through my tableView and select a new cell, the didDeselectRowAtIndexPath method fails onlet cell = tableView.cellForRowAtIndexPath(indexPath) as! ParticipantesSearchTableViewCell

At this point, I am debugging tableView.indexPathForSelectedRowand returning nil.

, , ? tableView.allowsMultipleSelection = true, , .

0

Source: https://habr.com/ru/post/1662682/


All Articles