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

BlackWolf

macrumors regular
Original poster
Apr 9, 2009
244
0
hi,
I was just trying to use NSInvocation, but I'm not getting it right.
I need to use this because I want to use a timer for a method that takes several arguments. The method signature of the method I want to call is:
Code:
-(void)moveToPosition:(CGPoint)newPosition animate:(BOOL)animate deckView:(UIView *)deckView;

After trying around a bit, it seems NSInvocation cannot take non-objects for arguments (it gives me "incompatible type for setArgument:atIndex:"). Because of that I created this method:
Code:
-(void)moveToPositionAtX:(NSNumber *)xPos Y:(NSNumber *)yPos animate:(NSNumber *)animate deckView:(UIView *)deckView {
    [self moveToPosition:CGPointMake([xPos floatValue],[yPos floatValue]) animate:[animate boolValue] deckView:deckView];
}

anyway, here is the code with NSInvocation which results in a crash and a EXC_BAD_ACCESS error on the line with NSInvocation *moveToPositionInvocation
Code:
SEL moveToPositionSelector = @selector(moveToPositionAtX:Y:animate:deckView:);
NSMethodSignature *moveToPositionSignature = [NSObject instanceMethodSignatureForSelector:moveToPositionSelector];
NSInvocation *moveToPositionInvocation = [NSInvocation invocationWithMethodSignature:moveToPositionSignature];
[moveToPositionInvocation setTarget:self];
[moveToPositionInvocation setSelector:moveToPositionSelector];
...
I guess the rest doesn't really matter because the code stops at the NSInvocation *moveToPositionInvocation line ... I just set the arguments after that and then pass the invocation to a timer.

ideas why my app crashes here?
 
Solved it.

For everyone who is interested:
you have to call
[[self class] instanceMethodSignatureForSelector:moveToPositionSelector]
instead of
[NSObject instanceMethodSignatureForSelector:moveToPositionSelector]
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.