How can I send two arguments in a selector method?

In the following, how can I send two arguments in togButton method? I tried, but it did not work.

[button addTarget:self action:@selector(togButton:) 


control targets only accept one argument for their actions: the control that's being manipulated. There's no way to do what you want (the OS just doesn't support it).

What are you trying to put in there? Maybe you can use the tag property, or if that's not sufficient, subclass UIButton and add instance variables that you can then access in -togButton:.

This is an example of a work around to get data from UI component

-(void) switchChanged:(id) sender
    UISwitch* switchControl = (UISwitch*)sender;
    UITableViewCell *cell = (UITableViewCell*)[sender superview];
    NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
    cell.textLabel.text =" change text title";

now you have cell and indexPath and you can do what you want. I hope I helped.

Also you can use structs to wrap your arguments in one parameter.

The best way to send two arguments to the method is to wrap them in a class. For example, if the two are arguments are strings then you would have a class solely comprised of string iVars.

[Class instancesRespondToSelector: @selector (setTo:over:)]

I am not an Objective-C guru, but I remember seeing this code in a book.

The action selector called by a button tap can have zero, one, or two parameters. The first is the sender (the button that was tapped) and the second is the event (the tap). See the target-action mechanism for controls:

- (void)action
- (void)action:(id)sender
- (void)action:(id)sender forEvent:(UIEvent *)event

As Thomas Müller suggests, the best way to pass app-specific data to your action selector is by subclassing UIButton (or, in the case of a button on a UITableViewCell, you can add the app-specific data to a UITableViewCell subclass and access the cell as the button's superview.superview).

Need Your Help

Classic ASP - Getting xml node's values from ResponseText

xml web-services xpath asp-classic nodes

From Classic ASP, how to get the particular xml node's values from the ResponseText which is in xml format returned as string ?

java fatal exception for android program

java android authentication cifs jcifs

i got the following exception when i run the code below. this is an android code, to access remote windows pc. it is used for download, upload and delete.when i run this code its throwing verificat...