Iphone 当类对象存储在数组中时,无法更改其属性,为什么不能?

Iphone 当类对象存储在数组中时,无法更改其属性,为什么不能?,iphone,arrays,class,properties,sprite,Iphone,Arrays,Class,Properties,Sprite,基本上,我创建一个数组,并向其中添加自定义类的实例。但是当我尝试访问存储在数组中的实例的属性时,我没有从类得到响应。顺便说一句,它适用于类的常规实例 //This works: Laser *myLaser = [[Laser alloc] initWithPosX:100 Y:150 node:self]; myLaser.sprite.rotation = 50; //This changes the sprite¨s (the sprite inside the class) rotat

基本上,我创建一个数组,并向其中添加自定义类的实例。但是当我尝试访问存储在数组中的实例的属性时,我没有从类得到响应。顺便说一句,它适用于类的常规实例

//This works:
Laser *myLaser = [[Laser alloc] initWithPosX:100 Y:150 node:self];

myLaser.sprite.rotation = 50; //This changes the sprite¨s (the sprite inside the class) rotation


//This doesnt:

Laser *aLaser = [[Laser alloc] initWithPosX:100 Y:150 node:self];

[Lasers addObject:aLaser]; //Lasers is a NSMutableArray declared in the .h

[aLaser release];

Laser *copyLaser = [Lasers objectAtIndex:0];

copyLaser.sprite.rotation = 50; //For some reason this doesnt work!

有人知道它为什么不起作用吗?使用NSMutableArray有问题吗?我的类是一个NSObject。

我在这里看到的问题是,
激光器未初始化,这里为零


您必须在某个地方初始化
激光器
(可能就在使用它之前,或者在视图控制器的init方法中)。使用
[[NSMutableArray alloc]init]

是否初始化了
激光器?它是否只包含
Laser
objects你刚才的评论,我投了赞成票..点评:惯例是用非大写的词来表示类,用大写的词来表示类。然后我会调用
激光
->
激光
。你也可以把它命名为lasersArray,以便更清晰。哇,谢谢你,真不敢相信我错过了:-)我同意这个名字。。回答得好!