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

Darkroom

Guest
Original poster
Dec 15, 2006
2,445
0
Montréal, Canada
recently i because quite disappointed when i learned that it's not possible to actually pass arguments with @selector() methods... i don't really know why that is, and it kinda pisses me off, but whatev...

so i'm trying to use NSInvocation to pass arguments thru a switch statement, but i need a little help. the following code isn't working:

Code:
NSUInteger tapCount = [[touches anyObject] tapCount];	
NSInvocation *invoke = [[NSInvocation alloc] init];
switch (tapCount)
	{
	case (2):	{
			[invoke setSelector:@selector(moveImage:withTouchPoint:withTapCount:)];
			[invoke setArgument:nil atIndex:0];
			[invoke setArgument:nil atIndex:1];
			[invoke setArgument:tapCount atIndex:2];
			[self performSelector:invoke withObject:nil afterDelay:kTapDelay];
			}
[COLOR="SeaGreen"]//etc.[/COLOR]

any thoughts?
 
You have set the first two arguments to nil. Does the method support that? Or does it assume that that they are valid non-nil values?

To let us help you: what, exactly, is not working? Describe in detail what is happening and what you expect to happen.
 
You don't need an invocation to use performSelector. I don't think your code will do what you expect.

Use a dictionary. Add your parameters to it and set the the withObject parameter to the dictionary.
 
You shouldn't set arguments 0 and 1. Just start your arguments at index 2. See the docs for the setArgument:atIndex: method for why this is. Even if you fix this, your usage of NSInvocation is incorrect.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.