Discussion in 'iOS Programming' started by BlackWolf, Apr 21, 2009.

  1. BlackWolf macrumors regular

    Apr 9, 2009
    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:
    -(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:
    -(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
    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?
  2. BlackWolf thread starter macrumors regular

    Apr 9, 2009
    Solved it.

    For everyone who is interested:
    you have to call
    [[self class] instanceMethodSignatureForSelector:moveToPositionSelector]
    instead of
    [NSObject instanceMethodSignatureForSelector:moveToPositionSelector]

Share This Page