NSInvocation in Objective C via delegate

I had some hard time finding the solution for a smooth usage of NSInvocation.
Furthermore I was to call a method within a delegate.

All's well that ends well and I am happy now.

Here is my code snippet.
My very last error was that I forgot to call the setSelector method :)

if (self.delegate)
SEL sel = @selector(fetchComplete:withParam1:withParam3:);
if (self.delegate!=nil && [self.delegate respondsToSelector:sel])
NSMethodSignature *sig = [[self.delegate class] instanceMethodSignatureForSelector:sel];
NSInvocation *inv = [NSInvocation invocationWithMethodSignature:sig];

[inv setSelector:sel];
[inv setTarget:self.delegate];
[inv setArgument:&Param1 atIndex:2];
[inv setArgument:&Param2 atIndex:3];
[inv setArgument:&Param3 atIndex:4];

[inv invoke];

// [self.delegate performSelector:@selector(fetchComplete:withParam1:withParam2:)
// withObject:elementtype
// withObject:Param2
// withObject:Param3
// ];

No comments:

Post a Comment