iOS sending parameter to selector using NSTimers

Is there a way to send a parameter to the selector via a NSTimer ?

myTimer =[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(removeTheNote:) userInfo:nil repeats:NO];

      - (void)removeTheNote:(NSString*)note
        NSLog(@"Note %@ ----------- REMOVED!",note);

I know that using :

myTimer =[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(removeTheNote:myNote) userInfo:nil repeats:NO];

doesn't work, so I am asking, is there a way to do this?


You can use the userInfo parameter for that:

myTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(removeTheNote:) userInfo:myNote repeats:NO];

But you will have to modify removeTheNote as follows:

- (void)removeTheNote:(NSTimer *)timer
    NSString *note = timer.userInfo;
    NSLog(@"%@", note);

Need Your Help

IE9 createElement and setting innerHTML dropping tags on a set operation?

javascript dom internet-explorer-9

Not sure if I am missing something obvious, as this is the first time I've tried to do much with raw DOM apis (as opposed to via jQuery, or such).

How deep is the Win32 message queue?

winapi message-queue

How many messages does the queue for a standard window hold? What happens when the queue overflows?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.