问题描述
我有一个类方法,我在其中创建和返回类对象.但我想在同一个类中访问该对象的某些属性.作为一个类方法,我不能在 .h 文件中声明变量,然后在其他方法中访问它.以下是代码如何在下面的实例方法中访问 backsprite 或 hudlayer 对象的值??
i have a class method in which i am creating and returning the class object. But i want to access certain properties of that object in the same class. Being a class method i cannot declare the variable in .h file and later access it in other methods. Following is the code How can i access the values of backsprite or hudlayer object in the instance method below??
我无法通过标签访问它,因为这里没有添加 + 方法中的 HUDlayer 对象,而是在调用该方法的另一个类中.
i am not able to access it via tags either as HUDlayer object in + method is not added here but in the other class which calls the method.
推荐答案
如果你有一个指向该类实例的指针/引用,你绝对可以在一个类的静态方法中访问该类的实例/成员变量.这是一个简单的例子...抱歉,如果有错别字...
You can absolutely in a static method of a class access instance/member variable of that class IF you have a pointer/reference to an instance of that class. Here is a simple example... sorry if there are typos...
//HUDLayer.h
// HUDLayer.h
//HUDLayer.m
// HUDLayer.m
//HelloWorldLayer.m(或任何地方)
// HelloWorldLayer.m (or wherever)
这篇关于从 iPhone & 中的类类型(+)方法访问对象Cocos2d?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!