类方法错误中访问实例变量“变量" [英] Instance variable 'variable' accessed in class method error

查看:123
本文介绍了类方法错误中访问实例变量“变量"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在头文件中声明了一个变量:

I have a variable declared in the header file :

@interface

@interface

int _nPerfectSlides;

@property (nonatomic, readwrite) int _nPerfectSlides;

,我有一个在标头中声明的方法:

and I have a method that I declared in the header :

+ (void) hit;

该方法中包含以下代码:

The method has the following code in it :

+ (void) hit {
    NSLog(@"hit");
    _nPerfectSlides = 0;
    [_game showHit];
}

现在由于某种原因,我收到错误在类方法中访问实例变量'_nPerfectSlides'"错误,看来我无法访问该方法内部的任何变量.我在做什么错了?

now for some reason I get the error "Instance variable '_nPerfectSlides' accessed in class method" error and it seems like I cant access any variables inside the method. What am I doing wrong?

推荐答案

如果您打算将此方法作为实例方法,请将+更改为-.

If you meant to make this an instance method, change that + to -.

这篇关于类方法错误中访问实例变量“变量"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆