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

后端 未结 8 624
离开以前
离开以前 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:23

    I don't know why I need to call the method superview twice to get the UITableViewCell.

    Update:

    Thank for Qiulang, now I got it.

    "That's because SDK now has added a private class called UITableViewCellContentView for UITableViewCell, which is button's superview now." – Qiulang

    UIButton *button = (UIButton *)sender;
    UITableViewCell *cell = (UITableViewCell *)button.superview.superview;
    UITableView *curTableView = (UITableView *)cell.superview;
    NSIndexPath *indexPath = [curTableView indexPathForCell:cell];
    

提交回复
热议问题