0

我之前查过几次,我尝试了答案所说的,但是当我运行 Xcode 的分析器时,它说相同的“消息表达式中的参数是一个未初始化的值”。这是 switch 语句:

`

NSString *imageFile;
switch (randomCoinType) {


    case 1:



        imageFile = @"coin.1.png";
        break;

    case 2:

        imageFile = @"coin.2.png";
        break;

    case 3:
    case 4:
        imageFile = @"coin.3.png";
        break;

    case 5:
    case 6:
    case 7:
    case 8:
        imageFile = @"coin.4.png";
        break;

    case 9:
        imageFile = @"coin.5.png";
        break;

    case 0:
        imageFile = @"coin.6.png";
        break;

    default: 

        break;


      }


//argument in message is uninitialized here!
Coins *c = [Coins spriteWithFile:imageFile];




c.type = type;
c.position = position;
c.velocity = ccp(0,0);
[coins addObject:c];
[self addChild:c z:2]; 

}

`

4

1 回答 1

1

如果您的default语句被调用,那么imageFile就是nil并且spriteWithFile不知道该怎么做。确保您要么处理nil传递的语句default,要么设置imagefile为默认情况下可用的内容。

于 2012-06-26T13:52:57.413 回答