小编baD*_*aDa的帖子

从NSTimer Interval = EXC_BAD_ACCESS访问NSArray

我有一些看起来像这样的代码:

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)

iphone cocoa objective-c

2
推荐指数
1
解决办法
1380
查看次数

检测Array中是否已启动一个位置

我需要检查一下特定的位置,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!

iphone cocoa-touch objective-c

1
推荐指数
1
解决办法
772
查看次数

标签 统计

iphone ×2

objective-c ×2

cocoa ×1

cocoa-touch ×1