Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

krmarien

macrumors newbie
Original poster
Jan 8, 2010
6
0
Hello,

I have created an instance of NSTimer:
Code:
	checkTimer = [[NSTimer scheduledTimerWithTimeInterval: (time * 0.1f) target:self selector:@selector(checkLoggedIn) userInfo:self repeats:true] retain];

But in the checkLoggedIn function I want to access functions of the where I create the timer. But how do I send these as parameters to the function checkLoggedIn.

Code:
	checkTimer = [[NSTimer scheduledTimerWithTimeInterval: (time * 0.1f) target:self selector:@selector(checkLoggedIn:) userInfo:self repeats:true withObject:@selector(fn1):@selector(fn2)] retain];
This doesn't work.

Thanks,
Kristof
 
I assume "I want to access functions of the where I create the timer" means "I want to be able to call methods on the object that created the timer". If it does then passing self as the userInfo is correct. You can simply call against the userInfo method in checkLoggedIn:. Note the :. It is very important: if you are passing a userInfo object you must code your method to expect this (typed as id). I'm pretty sure that's covered in the documentation.

Your second example is entirely nonsensical.
 
Ok, but how do I get the selector of a funtion inside checkLoggedIn?

Code:
- (void)checkLoggedIn:(id)sender
{
	check = [CheckLoggedIn alloc];
	[check checkLoggedIn:sender loggedInSelector:@selector([sender loggedIn]) notloggedInSelector:@selector([sender notLoggedIn])];
}
This doesn't work
 
Selectors don't know about objects. Think of them as strings. You just create and pass them around wherever you want, without knowledge of an object or class.

You may want to read up on them, as your syntax is slightly off:
http://developer.apple.com/mac/libr...nceptual/ObjectiveC/Articles/ocSelectors.html

If you want to send selectors as arguments to a timer, the easiest way is to use NSStringFromSelector and if you have more than one, use a dictionary.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.