OGeek|极客世界-中国程序员成长平台

标题: ios - 如何调用按钮 Action 取决于uiTableView中的标签? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 09:29
标题: ios - 如何调用按钮 Action 取决于uiTableView中的标签?

我在单个单元格中有一个按钮,并为该按钮设置标签。

按钮向上箭头创建:

UIButton *btn_uparrow=[[UIButton alloc]initWithFrame:CGRectMake(500, 20, 50, 50)];
[btn_uparrow setTitle"up" forState:UIControlStateNormal];
btn_uparrow.backgroundColor =[UIColor blackColor];
[btn_uparrow addTarget:self actionselector(btn_up_arrow forControlEvents:UIControlEventTouchUpInside];
[btn_uparrow setTag:indexPath.row];
[cell addSubview:btn_uparrow];

上箭头按钮操作方法

-(void)btn_up_arrowUIButton*)click
{
 i++;
 NSLog(@"increment %d",i);
  if(i>=5)
  {
    NSLog(@"button increment %d",i);
    i--;
  }
}

当我单击单独单元格中的按钮时,增量将继续在以前的数据上。



Best Answer-推荐答案


请使用以下代码。

NSInteger tagVal = (UIButton*)click.tag;

并检查 tagVal 变量值。

关于ios - 如何调用按钮 Action 取决于uiTableView中的标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31781332/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4