本文介绍了使用NSTimer的探针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 NSTimer 问题.我收到"SIGABRT"错误和 [NSCFTimer intValue]:无法识别的选择器已发送到实例

I have a problem with a NSTimer.I received a "SIGABRT" error and [NSCFTimer intValue]: unrecognized selector sent to instance

这些是我的代码:

-(void)detectionMove:(NSNumber*)arrayIndex{


    static BOOL notFind = FALSE;
    static int countVariable = 0;
    static int countRilevamenti = 0;

    notFind = FALSE;

    for(int i = countVariable+1; i<[[[[sharedController arrayMovement]objectAtIndex:[arrayIndex intValue]] arrayPositionMove]count]; i++){

        if(!notFind){

            if((actualAccelerometerX+sensibilityMovement) >= [[[[[sharedController arrayMovement]objectAtIndex:[arrayIndex intValue]] arrayPositionMove]objectAtIndex:i]valueX] && (actualAccelerometerX-sensibilityMovement) <= [[[[[sharedController arrayMovement]objectAtIndex:[arrayIndex intValue]] arrayPositionMove]objectAtIndex:i]valueX] &&
               (actualAccelerometerY+sensibilityMovement) >= [[[[[sharedController arrayMovement]objectAtIndex:[arrayIndex intValue]] arrayPositionMove]objectAtIndex:i]valueY] && (actualAccelerometerY-sensibilityMovement) <= [[[[[sharedController arrayMovement]objectAtIndex:[arrayIndex intValue]] arrayPositionMove]objectAtIndex:i]valueY] &&
               (actualAccelerometerZ+sensibilityMovement) >= [[[[[sharedController arrayMovement]objectAtIndex:[arrayIndex intValue]] arrayPositionMove]objectAtIndex:i]valueZ] && (actualAccelerometerZ-sensibilityMovement) <= [[[[[sharedController arrayMovement]objectAtIndex:[arrayIndex intValue]] arrayPositionMove]objectAtIndex:i]valueZ])
            {
                countVariable = i;
                notFind = TRUE;
                countRilevamenti++;
            }
        }
    }

    if(!notFind)
        return;

    else if(countVariable+1 == [[[[sharedController arrayMovement]objectAtIndex:[arrayIndex intValue]]  arrayPositionMove]count]){

        if(countRilevamenti + tollerance >= [[[[sharedController arrayMovement]objectAtIndex:[arrayIndex intValue]] arrayPositionMove]count])
            movementDetected = [arrayIndex intValue];
        else
            NSLog(@"troppo veloce");

        countVariable = 0;
        notFind = FALSE;
        countRilevamenti = 0;       

        return;
    }

    [NSTimer scheduledTimerWithTimeInterval:timeToCatch target:self selector:@selector(detectionMove:) userInfo:(NSNumber*)arrayIndex repeats:NO];      
}

推荐答案

您的方法签名错误

- (void)timerFireMethod:(NSTimer*)theTimer

不是 NSNumber

-edit2-

NSMutableDictionary *myDictionary = [[NSMutableDictionary alloc] init];  
[myDictionary setObject:arrayIndex forKey:@"index"];
[NSTimer scheduledTimerWithTimeInterval:timeToCatch target:self selector:@selector(detectionMove:) userInfo:myDictionary repeats:NO];  

-编辑-

如果要保留旧方法,以便可以使用 NSNumber 参数从其他地方调用它,则必须为 NSTimer 创建一个新方法来调用和然后在 NSTimer 方法的实现中,使用适当的数字调用 NSNumber 方法.

If you want to keep your old method so you can call it from somewhere else with a NSNumber argument you have to create a new method for the NSTimer to call and then in the implementation of the NSTimer method you call the NSNumber method with whatever number that is appropriate.

-(void)detectionMove:(NSNumber*)arrayIndex{
 // still does whatever
}

-(void)automaticDetectionMove:(NSTimer*)theTimer{
 [self detectionMove:whatevernumber];
}

// update with new method name
[NSTimer scheduledTimerWithTimeInterval:timeToCatch target:self selector:@selector(automaticDetectionMove:) userInfo:(NSNumber*)arrayIndex repeats:NO];

这篇关于使用NSTimer的探针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-18 17:30