AMI amitekh AMI amitekh - 1 year ago 116
Objective-C Question

How to pass two arguments to a UIButtons target method in iOS?

In my code I've to pass two arguments to targetMethod

, I can pass the button.tag as one argument and how to pass the other argument?

Please Give an Example.

My code:

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


Answer Source

If you want the indexPath on button action then try something like this.


     CGPoint point = [sender.superview toView:self.tableView];
     NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:point];
     if (indexPath) {
          NSLog(@"Section - %ld Row - %ld",deleteIndexPath.section, deleteIndexPath.row);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download