您好我正在编写一个应用程序,我想创建一个字符串。
所以我用那个
NSString *scoreString;
NSString *cupCakesPassedString;
NSString *cupCakes;
int cupCakesPassed;
int totalCupCakesPerLevel;
-(void)spriteMoveFinished:(id)sender {
CCSprite *sprite = (CCSprite *)sender;
[self removeChild:sprite cleanup:YES];
if (sprite.position.y <= 0) {
sprite.position = ccp( sprite.position.x,768 );
score+=5;
scoreString=[NSString stringWithFormat:@"%i",score];
[label setString:scoreString];
cupCakesPassed++;
cupCakesPassedString=[NSString stringWithFormat:@"%i",cupCakesPassed];
cupCakes=[[cupCakesPassedString stringByAppendingString:@"/"]stringByAppendingString:totalCupCakes];
[passingCupCakes setString:cupCakes];
}
}
它崩溃了!但是如果使用像 scoreString 这样的另一个字符串,它可以工作......
在初始化方法中我有
totalCupCakesPerLevel=30;
scoreString=[NSString stringWithFormat:@"%i",score];
cupCakesPassedString=[NSString stringWithFormat:@"%i",cupCakesPassed];
totalCupCakes = [NSString stringWithFormat:@"%i",7];
cupCakes=[[cupCakesPassedString stringByAppendingString:@"/"]stringByAppendingString:totalCupCakes];
如果我这样做
cupCakes=[[cupCakesPassedString stringByAppendingString:@"/"]stringByAppendingString:scoreString];
我也有 init 方法
cupCakes=[[cupCakesPassedString stringByAppendingString:@"/"]stringByAppendingString:totalCupCakes];
并且实际上有效......直到调用该方法。
数字可能是错误的,但出于测试目的,问题似乎出在字符串totalCupCakes上,因为即使我使用@“test”有效,但该字符串有什么问题?