Detecting which UIButton was pressed in a UITableView

前端 未结 26 3334
小蘑菇
小蘑菇 2020-11-22 00:40

I have a UITableView with 5 UITableViewCells. Each cell contains a UIButton which is set up as follows:

- (UITableView         


        
26条回答
  •  我寻月下人不归
    2020-11-22 01:04

    I would use the tag property like you said, setting the tag like so:

    [button setTag:indexPath.row];
    

    then getting the tag inside of the buttonPressedAction like so:

    ((UIButton *)sender).tag
    

    Or

    UIButton *button = (UIButton *)sender; 
    button.tag;
    

提交回复
热议问题