我有一些看起来像这样的代码:
actualColor = 0;
targetColors = [NSArray arrayWithObjects:[UIColor blueColor],
[UIColor purpleColor],
[UIColor greenColor],
[UIColor brownColor],
[UIColor cyanColor], nil];
timer = [NSTimer scheduledTimerWithTimeInterval:3.0
target:self
selector:@selector(switchScreen)
userInfo:nil
repeats:YES];
Run Code Online (Sandbox Code Playgroud)
在选择器中我有这个:
- (void) switchScreen
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelegate:self];
int totalItens = [targetColors count];
NSLog(@"Total Colors: %i",totalItens);
if(actualColor >= [targetColors count])
{
actualColor = 0;
}
UIColor *targetColor = [targetColors objectAtIndex:actualColor];
if(!firstUsed)
{
[firstView setBackgroundColor:targetColor];
[secondView setAlpha:0.0];
[firstView setAlpha:1.0];
firstUsed = YES;
}
else
{
[firstView setBackgroundColor:targetColor];
[secondView setAlpha:1.0];
[firstView setAlpha:0.0]; …Run Code Online (Sandbox Code Playgroud) 我需要检查一下特定的位置,NSArray看看它们是否已经初始化,但我遇到了麻烦.我尝试执行以下操作,但它会导致我的应用程序崩溃!
if ((NSMutableArray *)[arrAllBlocks objectAtIndex:iLine] == nil)
{
[arrAllBlocks insertObject:[[NSMutableArray alloc] init] atIndex:iLine];
}
NSMutableArray *columArray = (NSMutableArray *)[arrAllBlocks
objectAtIndex:iLine];
[columArray insertObject:newBlock atIndex:iColumn];
Run Code Online (Sandbox Code Playgroud)
这样做最好的是什么?我已经尝试了一些像这样的方法isValid!