Call "sender id" in Xcode

Here is the method I want to name:

- (void)myMethod:(id)sender {

What would I call it? I tried:

[self myMethod]

^ error: The expected expression before the marker "]".

I know this is a simple question, but I'm new to iPhone development

+3
source share
3 answers

The method takes one parameter, so you must provide it. If you don't have the sender you want to give, just pass nil:

[self myMethod:nil];

You can also overload the method as a convenience:

// declarations
- (void)myMethod;
- (void)myMethod:(id)sender;

// implementations
- (void)myMethod { [self myMethod:nil]; }
- (void)myMethod:(id)sender { /* do things */ }
+12
source

If you do not want to send an object of indefinite type to your method, you do not need a part (id)sender:

- (void)myMethod {

}
+4
source

, .

[self myMethod:something]

, , .

+1
source

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


All Articles