开发者

Adding arguments to selector in addTarget

开发者 https://www.devze.com 2023-03-08 02:51 出处:网络
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'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开发者_StackOverflow: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)sender can be cast to your custom button and you can obtain the set values.


Why not global variables or properties in your class?

0

精彩评论

暂无评论...
验证码 换一张
取 消