This question already has answers here:
Pass multiple parameter using cell button action

(1个答案)



How to know the UITableview row number

(10个答案)


3年前关闭。




在我的代码中,我必须将两个参数传递给targetMethod printMethod,我可以将button.tag作为一个参数传递,如何将另一个参数传递?

请举一个例子。

我的代码:
 button.tag = indexPath.row;
 secondArgument = indexPath.section;
 [button addTarget:self action:@selector(printMethod:) forControlEvents:UIControlEventTouchUpInside];

-(IBAction)printMethod:(UIButton*)sender{
    NSLog(@"%d%d",sender.tag,//SecondArgument);
}

最佳答案

如果您想在按钮上操作indexPath,请尝试这样的操作。

-(IBAction)printMethod:(UIButton*)sender{

     CGPoint point = [sender.superview convertPoint:sender.center toView:self.tableView];
     NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:point];
     if (indexPath) {
          NSLog(@"Section - %ld Row - %ld",deleteIndexPath.section, deleteIndexPath.row);
     }
}

关于ios - 如何在iOS中将两个参数传递给UIButtons目标方法? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40018151/

10-11 23:35