Calling a method that is also used by UIButton?

I have a small iPhone application in which I created a button with some functionality. My question is: how can I call this button without clicking on it?

Any help would be appreciated!

thanks

+3
source share
3 answers

Call button function. You can also manually call the function yourself.

Example:

- (void) btnFunction {
  NSLog (@"test");
}

...

UIButton *btn1 = [UIButton buttonWithType:UIButtonRoundedRect];
// other code to set up button goes here
[btn1 addTarget:self action:@selector(btnFunction) forControlEvents:UIControlEventTouchUpInside];

You can also call the function yourself:

[self btnFunction];
+2
source

If you want to activate any target that the button is connected to, you can call:

[button sendActionsForControlEvents:UIControlEventTouchUpInside];

(TouchUpInside - , ). , (, ), .

UIControl, UIButton, ...

+4

, ( ...).

.

. IBAction . IBAction - :

- (void) doSomething:(id)sender

:

[controller doSomething:self];

, .

+1

Source: https://habr.com/ru/post/1716228/


All Articles