-(void)Aray
{
NSMutableArray *ColorArray = [[NSMutableArray alloc] init];
if(Counter < NewColor)
{
[ColorArray addObject:[NSNumber numberWithInteger:ColorTemp]];
Counter += 1;
}
}
-(IBAction)Go:(id)sender
{
NSMutableArray *ColorArray = [[NSMutableArray alloc] init];
Color = [[ColorArray objectAtIndex:Index] intValue];
if(Color == 2)
{
ColorLabel.text = @"The Color is Black";
Screen.image = [UIImage imageNamed:@"BlackTile.png"];
}
else
{
Screen.image = [UIImage imageNamed:@"Tunnel.png"];
ColorLabel.text = @"The Color is Green";
}
Index += 1;
}
-(IBAction)Black:(id)sender
{
ColorTemp = 2;
NewColor += 1;
[self Array];
}
-(IBAction)Green:(id)sender
{
ColorTemp = 1;
NewColor += 1;
[self Array];
}
答案 0 :(得分:1)
问题是ColorArray
需要是类的实例变量(或@property
),以便它在方法调用的外。
无论Index
的值如何,此代码都会始终崩溃:
NSMutableArray *ColorArray = [[NSMutableArray alloc] init];
Color = [[ColorArray objectAtIndex:Index] intValue];
Color
似乎已经是一个实例变量(或@property
),所以这个概念对你来说不应该是陌生的。
附注:变量通常以小写字母开头并使用camal-case命名。