I am trying to build an iPhone app. I created a
method like this:
- (void)score {
// some code
}
and I have tried to call it in an other method like this:
- (void)score2 {
@selector(score);
}
But it does not work. So, how do I call a method correctly?
-
I think what you're trying to do is:
-(void) score2 { [self score]; }The [object message] syntax is the normal way to call a method in objective-c. I think the @selector syntax is used when the method to be called needs to be determined at run-time, but I don't know objective-c well enough to give you more information on that.
Chuck : @selector gives you the "name" of a method in a form that Objective-C can use to send messages. It's used somewhat analogously to a function pointer. -
I suggest you read The Objective-C Programming Language. The part about messaging is specifically what you want here, but the whole thing will help you get started. After that, maybe try doing a few tutorials to get a feel for it before you jump into making your own apps.
-
To send an objective-c message in this instance you would do
[self score];I suggest you read the Objective-C programming guide Objective-C Programming Guide
0 comments:
Post a Comment