NSMutableArray根本不起作用 [英] NSMutableArray not working at all

查看:95
本文介绍了NSMutableArray根本不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将精灵添加到NSMutableArray,但没有添加它们.这就是我所拥有的:

I'm trying to add sprites to a NSMutableArray but it's not adding them. This is what I have:

NSMutableArray *tail;
CCSprite *block;
int j;
-(void)handleTail:(CCSprite*)pos{
    CGPoint point= pos.position;
    block = [CCSprite spriteWithFile:@"Icon-Small-50.png"];
    //Adding the tail blocks
    block.scale = .8;
    block.color = ccGREEN;
    block.position = point;
    NSLog(@"Block Pos (%f,%f)",block.position.x,block.position.y);

    //CGPoint playerPos = piece.position;

    originalPos = point;

    if ([tail count] < maxLength) {
        [tileMap addChild:block];
        [tail addObject:block];
        NSLog(@"Tail length:%i",tail.count);
        j+=1;
    }
    if (j == 3) {
        NSLog(@"J called");
        [tail removeObjectAtIndex:0];
    }   
}

我不明白为什么这不起作用?

I don't understand why this isn't working?

推荐答案

您尚未分配+初始化tail.

在awakeFromNib或init或viewDidLoad(适用于您的类)中使用

In awakeFromNib or init or viewDidLoad ( which ever is applicable for your class) use

tail=[[NSMutableArray alloc] init];


建议注意:尝试遵循命名约定.


Suggestion NOTE : Try to follow naming convention.

由于tail是一个数组(复数),因此应使用tails.

As tail is an array (plural) you should use tails.

这篇关于NSMutableArray根本不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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