iOS - passing arguments in action:@selector()

后端 未结 3 1515
臣服心动
臣服心动 2020-12-18 11:12

I\'m adding a button to a UITableViewCell programmatically. The method to be run when the button is pressed is - (void) quantityDown:(id)sender rowNumber:(int)rowNum<

3条回答
  •  囚心锁ツ
    2020-12-18 12:06

    Set each button tag as indexPath.row. Then just declare the function:

    - (void)quantityDown:(id)sender
    

    In that method do this:

    UIButton *btn = (UIButton *)sender;
    

    Add target like this:

    [buttonDown addTarget:self action:@selector(quantityDown:) forControlEvents:UIControlEventTouchUpInside];
    

    From btn.tag you can get the row number. Hope this helps. :)

提交回复
热议问题