S
S
Sergey Sulakov2016-07-02 12:49:30
Objective-C
Sergey Sulakov, 2016-07-02 12:49:30

Handling button clicks?

Good day everyone! This question arose when designing the application:
There are, for example, 10 buttons. You need to "respond" to pressing any of the buttons. I know how to respond to pressing a certain button (right-click - drag it to the implementation).
But how to create a click event on any of the buttons and when you click on it, for example, display its text in a text label?
In jQuery, this is $(this) or setting onclick="func()" on each element, and then define this func()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Globak, 2016-07-04
@web-verzus-team

If you do it through code, then you create a button and then bind an action to it.

UIButton *button  = [[UIButton alloc] init];
[button addTarget:self action:@selector(pushButton:) forControlEvents:UIControlEventTouchUpInside];

and then create the pushButton method (the one specified in the action)
- (void)pushButton:(id)sender{
//code 
}

If you do it through a storyboard, then
- (IBAction)refresh:(id)sender{
 //Code
}

right-click on the button and drag to this function or to an empty code and in the window that appears, select Action and xcode will create a similar function itself

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question