Why is my method not found?
In my h file I have
+(CCRenderTexture*) createStroke: (CCLabelTTF*) label
size:(float)size
color:(ccColor3B)cor;
In my m file I implemented this method and use it like
CCRenderTexture* stroke = [self createStroke:pause size:3 color:ccBLACK];
But it gives me a warning "method not foun开发者_如何学Pythond". Why?
Since the +createStroke
is a class method, you can't call it on self
. You should instead send that message to the CCRenderTexture
class.
So, in your case, if self
is of the CCRenderTexture
type, you could just replace it with self.class
. (So that when you will subclass, the overridden method will be called by the superclass)
If it is not, write something like:
CCRenderTexture* stroke = [CCRenderTexture createStroke:pause size:3 color:ccBLACK];
plus means it is a class method, so you need to use the Class Name instead of an instance of that class: [ClassName createStroke:pause size:3 color:ccBLACK] You probably want to have an instance method, so put a minus instead of plus in your declaration.
Here is some more info on this topic: What is the difference between class and instance methods?
精彩评论