Search code examples
parametersuibuttonnsstringactionaddtarget

How to subclass an UIButton to pass multiple NSString parameters via addTarget:action:forControlEvents


I have to programmatically define (without using any IBAction) a UIButton that when tapped gets the values of 3 NSString parameters and executes a Segue. The method used for executing the Segue is called via:

[myButton addTarget:self action:@selector(myButtonTapped:) forControlEvents:UIControlEventTouchUpInside];

And then executed as:

-(void)myButtonTapped {
[self performSegueWithIdentifier:@"showNewFromOld" sender:self];}

I understand that the best solution would be to subclass the UIButton (myButton in my case) in order to pass via the sender the 3 NSString as found in this answer: Passing parameters to addTarget:action:forControlEvents Unfortunately I cannot comment this given my newbie level and I would really appreciate some help from the community on this.


Solution

  • The solution I found simply involves the definition of a class method visible to other classes:

    +(void)myMethod:...