iOS get specific UITableViewCell

后端 未结 5 1717
眼角桃花
眼角桃花 2021-01-23 16:55

I have a UIButton in a custom UITableViewCell. This button triggers an event when clicked.

[myButton addTarget:self action:@selector(b         


        
5条回答
  •  面向向阳花
    2021-01-23 17:17

    As you rightly say, the button is "in" the cell - in the sense that it is a subview, at some depth, of some cell. So simply walk up the view hierarchy until you reach the cell:

    - (void) buttonClicked:(id)sender {
        UIView* v = sender;
        while (![v isKindOfClass:[UITableViewCell class]])
            v = v.superview;
        // now v is the cell
    }
    

提交回复
热议问题