views:

101

answers:

2

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

These is my code:

-(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];      
}
A: 

You have the wrong signature for your method

- (void)timerFireMethod:(NSTimer*)theTimer

not NSNumber

--edit2--

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

--edit--

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];
willcodejavaforfood
no... I want pass a NSNumber at these method...
zp26
Then it wont work with NSTimer. NSTimer would not know which number you want to pass to that method anyway. Does that make sense?
willcodejavaforfood
but [NSTimer scheduledTimerWithTimeInterval:timeToCatch target:self selector:@selector(automaticDetectionMove:) userInfo:(NSNumber*)arrayIndex repeats:NO];is into -(void)automaticDetectionMove:(NSTimer*)theTimer{} method? or not?
zp26
No you have to create your own dictionary and send it to the NSTimer, see update2
willcodejavaforfood
A: 

NSTimer fire methods must have the signature:

- (void)myMethod:(NSTimer *)timer;

The timer passes itself as an argument to the method you set.

If you want extra parameters, set them in the user info dictionary, and then retrieve them using their key using:

[[timer userInfo] objectForKey:@"myUserInfoParamterKey"];

So as an example, you should be setting your NSNumber object in your user info and retrieving it that way, not passing it as a parameter to the timer method.

Jasarien
can you post the solution for my code please?
zp26