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

后端 未结 8 629
离开以前
离开以前 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];
    

提交回复
热议问题