Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSTimer userInfo. How object is passing to the selector?

I have this code:

-(void)startRotation:(RDUtilitiesBarRotation)mode {
    rotationTimer = [NSTimer scheduledTimerWithTimeInterval:0.1f target:self selector:@selector(rotateSelectedItem:) userInfo:[NSNumber numberWithInt:mode] repeats:YES];
}
-(void)rotateSelectedItem:(NSNumber*)sender {
    float currAngle = [selectedItem currentRotation];
    if ([sender intValue] == RDUtilitiesBarRotationLeft) {
        [selectedItem rotateImage:currAngle - 1];
    }
    else {
        [selectedItem rotateImage:currAngle + 1];
    }
}
-(void)stopRotation {
    [rotationTimer invalidate];
    rotationTimer = nil;
}

The target is start rotating a view while user holds a button. When user releases it the timer will stop.

But I'm giving this:

-[__NSCFTimer intValue]: unrecognized selector sent to instance 0x4ae360

But if I'm paasing in userInfo a NSNumber class, why I'm receiving the timer?

Thanks.

like image 358
NemeSys Avatar asked Mar 01 '12 19:03

NemeSys


1 Answers

Your timer action method should look like this

-(void)rotateSelectedItem:(NSTimer*)sender

You can get at the userInfo by doing

NSNumber *userInfo = sender.userInfo;
like image 96
joerick Avatar answered Nov 15 '22 07:11

joerick