Swift TableView segue to new ViewController with wrong index path (penultimate selection)

后端 未结 2 1590
南方客
南方客 2021-01-27 02:08

I have a weird problem. I have two TableViews one for showing Projects and one for showing all Team Members. With both TableViews I have the same bug.

When a user click

2条回答
  •  遥遥无期
    2021-01-27 02:33

    This is one of those errors we've all made at some point, usually by not reading the autocomplete carefully.

    Your code is

        func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath)
    
    

    You've used the didDeselectRowAt rathert than didSelectRowAt method. Which means that it runs it when that row loses focus (which will be when you click on another row).

    You need

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

提交回复
热议问题