didSelectRowAtIndexPath returns wrong IndexPath

前端 未结 2 2022
半阙折子戏
半阙折子戏 2021-02-06 20:33

I have encountered a really puzzling bug. The first row of my UITableView returns 1 and the second one returns 0 in the indexPath! How is t

相关标签:
2条回答
  • 2021-02-06 20:53

    Despite the title, the overloaded method is in fact didDeselectRowAtIndexPath, so it sounds like the behaviour is correct -- when the 1th row is touched, the 0th becomes deselected, and vice versa.

    0 讨论(0)
  • 2021-02-06 20:56

    You have implemented didDeselectRowAtIndexPath. It will be fired when the row is no longer selected.

    When you touch the second row, the first row is no longer selected, so [0, 1] will be shown.
    When you touch the first row again, the second row is now no longer selected, so [0, 0] will be shown.

    These are totally expected.

    Implement didSelectRowAtIndexPath if you need it to respond when the row is selected.

    -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        //                                       ^
        ...
    
        NSLog(@"IndexPath: %@", [indexPath description]);
    }
    
    0 讨论(0)
提交回复
热议问题