tags:

views:

29

answers:

2

How to use the userInfo in + (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)ti target:(id)aTarget selector:(SEL)aSelector userInfo:(id)userInfo repeats:(BOOL)yesOrNo;

I want to send certain parameters to my custom selector.

+1  A: 

The userInfo parameter is for just that.

- (void)onTimer:(NSTimer *)timer 
{
   NSLog(@"User Info %@", [timer userInfo] );
}
jojaba
A: 

The difficulty is that you need to wrap your parameters, even if more than 1, even if they aren't objects, into a single object. Creating a temporary NSDictionary, and stuffing it with keyed parameters works. Or you could create an custom class just to hold the required parameters, and create and fill an object of that class (alloc, initWithMy42Parameters:) to pass as the userInfo.

hotpaw2
Thanks. It worked.
Abhinav