“‘这个’的使用无效”在非成员函数中”在 Objective-C 环境中?
使用 Xcode。
在此代码中(func 在接口中声明),告诉 subj 错误,用“self”站在字符串上。
+ (void) run: (Action) action after: (int) seconds
{
[self run:action after:seconds repeat:NO];
}
什么……?
Using Xcode.
In this code (func is declared in interface), tells subj error, standing on string with 'self'.
+ (void) run: (Action) action after: (int) seconds
{
[self run:action after:seconds repeat:NO];
}
What the... ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
self
是一个实例变量,用于引用当前对象的实例。您正尝试在类级别方法
+(void)...
中使用它,其中self
没有任何意义。尝试使用共享实例,或将相关类的实例传递给该方法。编辑
我的评论者指出
self
在类级别上下文中确实有意义,但它指的是类本身。这意味着您试图调用如下所示的方法:您的目标应该是:
self
is an instance variable used to refer to an instance of the current object.You are attempting to use it in a class level method
+(void)...
whereself
has no meaning. Try using a shared instance, or passing an instance of the class in question to the method.EDIT
My commenters have pointed out that
self
does have meaning in class level contexts, but it refers to the class itself. That would mean you were trying to call a method that looks like this:Where you should be aiming for: