Answer the question
In order to leave comments, you need to log in
How to detect a button click?
Hello! the question may seem stupid, ridiculous, but I appeal to the court because I did not find an answer to it. I met several languages \u200b\u200bin which this method works fine, but this was not found here. It is necessary to determine which button was pressed, that is, if (button. click){bla bla bla} with the help of such a small code it was possible to define this action, can you tell me with what help such an action was implemented in objective c?
Answer the question
In order to leave comments, you need to log in
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
[button addTarget:self action:@selector(myLovelyFunction:) forControlEvents:UIControlEventTouchUpInside];
[button setTitle:@"Touch me, baby!" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
[view addSubview:button];
- (void)myLovelyFunction:(id)sender {
// do something
}
- (void)myLovelyFunction:(id)sender {
UIButton *button = (UIButton*)sender;
if (button.tag == 91) {
// super
} else {
// good too
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question