How can I keep track of the index path of a button in a table view cell?

后端 未结 8 615
离开以前
离开以前 2020-12-08 02:37

I have a table view where each cell has a button accessory view. The table is managed by a fetched results controller and is frequently reordered. I want to be able to press

相关标签:
8条回答
  • 2020-12-08 03:36

    If you feel uncomfortable relying on button.superview, this method should be a little more robust than some of the other answers here:

    UIButton *button = (UIButton *)sender;
    CGRect buttonFrame = [button convertRect:button.bounds toView:self.tableView];
    NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:buttonFrame.origin];
    
    0 讨论(0)
  • 2020-12-08 03:41

    Use this Perfect working for me.

    CGPoint center= [sender center];
    CGPoint rootViewPoint = [[sender superview] convertPoint:center toView:_tableView1];
    NSIndexPath *indexPath = [_tableView1 indexPathForRowAtPoint:rootViewPoint];
    NSLog(@"%@",indexPath);
    
    0 讨论(0)
提交回复
热议问题