didSelectRowAtIndexPath returns wrong IndexPath

前端 未结 2 2021
半阙折子戏
半阙折子戏 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: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]);
    }
    

提交回复
热议问题