I’m having trouble adding arguments to the selector of a button (programmatically created). I’ve looked around the internet and tried some things, but I can’t figure it out.
I create a button with the following line:
NSString *someThing = [[NSString alloc] initWithString:@"someThing"];
int counter = 4;
[anotherButton addTarget:self action:@selector(alertPressed:) forControlEvents:UIControlEventTouchUpInside];
I’ve got the function alertPressed:
-(void)alertPressed:(id)sender {
}
How can I transfer those two variables to alertPressed?
You can subclass
UIButton, with a custom button that contains those attributes. Then, your(id)sendercan be cast to your custom button and you can obtain the set values.