DarkLeafyGreen
DarkLeafyGreen

Reputation: 70416

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 found". Why?

Upvotes: 0

Views: 5679

Answers (2)

Nostradamus
Nostradamus

Reputation: 658

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?

Upvotes: 2

eugeniodepalo
eugeniodepalo

Reputation: 801

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];

Upvotes: 7

Related Questions