Using the IBAction method when it is not called from an action?

Are there any problems when using IBAction when it is not actually called from a user action?

If you have an action like

-(IBAction)sayHello:(id)sender;

You can call it from your class, for example:

[self sayHello:@"x"]

@ "x" does nothing, it just populates for the sender.

In fact, you can create an IBAction method without the (id) sender

-(IBAction)sayHello;

and call it from both user actions and code, but then you will not get any useful sender information from the interface. What is the “correct” padding method for the sender when called from code? And can you create sender information for sending when it is called from code?

Just trying to figure it out.

+3
3

, - (IBAction) SayHello: (ID) ;

, : - (void) sayHello; - (IBAction) sayHello: (id) { [self sayHello]; }

sayHello: (id) - , sayHello. . ,

+6

. , , UIButton...

UIButton *button;

:

[self sayHello:button];

, , - , , , - . , .

+3

If you really aren't using a parameter sender(see Jaanus answer for more info on this), you're fine with passing nilfor it when you call the method from code.

+2
source

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


All Articles