为什么我的方法没有找到?
在我的 h 文件中,
+(CCRenderTexture*) createStroke: (CCLabelTTF*) label
size:(float)size
color:(ccColor3B)cor;
我在 m 文件中实现了此方法并使用它,
CCRenderTexture* stroke = [self createStroke:pause size:3 color:ccBLACK];
但它给了我一个警告“找不到方法”。为什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于
+createStroke
是一个类方法,因此您无法在self
上调用它。您应该将该消息发送到 CCRenderTexture 类。因此,在您的情况下,如果
self
属于CCRenderTexture
类型,您只需将其替换为self.class
即可。 (这样当你创建子类时,超类将调用重写的方法)如果不是,请编写如下内容:
Since the
+createStroke
is a class method, you can't call it onself
. You should instead send that message to theCCRenderTexture
class.So, in your case, if
self
is of theCCRenderTexture
type, you could just replace it withself.class
. (So that when you will subclass, the overridden method will be called by the superclass)If it is not, write something like:
加号表示它是一个类方法,因此您需要使用类名而不是该类的实例: [ClassName createStroke:pause size:3 color:ccBLACK]
您可能想要一个实例方法,因此在声明中添加减号而不是加号。
以下是有关此主题的更多信息:类方法和实例方法之间有什么区别?< /a>
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?