问题
Here is the method I wish to call:
- (void)myMethod:(id)sender {
How would I call it? I tried:
[self myMethod]
^error: Expected Expression before "]" token.
I know this is a simple question, but I am new to iPhone Development
回答1:
The method takes one parameter, so you have to give it one. If you have no sender you want to give, just pass nil:
[self myMethod:nil];
You could 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 */ }
回答2:
Unless you wanted to send an unspecified-type object to your method you don't need the (id)sender portion:
- (void)myMethod {
}
回答3:
You need to pass along a sender when you call it.
[self myMethod:something]
In other words, you need to have an argument to pass along when you call the method.
来源:https://stackoverflow.com/questions/4456115/call-idsender-method-in-xcode