Im trying to call showUIAlertView from myMethod but get an exception: Terminating app due to uncaught
exception ‘NSInvalidArgumentException’, reason: ‘+[NSInvocation invocationWithMethodSignature:]: method signature argument cannot be nil’
Also,please tell what to write as argument for setTarget in line “[invocation setTarget:self];”, i wrote self as both the methods are in the same file.
thanks!!
- (void)showUIAlertView:(NSString*)title:(NSString*)message
{
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:title
message:message
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
- (void)myMethod:(NSString*)someData
{
//some lines of code
SEL selector = @selector(showUIAlertView:title:);
NSMethodSignature *signature = [[self class] instanceMethodSignatureForSelector:selector];
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
[invocation setSelector:selector];
NSString *str1 = @"Status Message";
NSString *str2 = @"You are not a member yet.";
[invocation setTarget:self];
[invocation setArgument:&str1 atIndex:2];
[invocation setArgument:&str2 atIndex:3];
[NSTimer scheduledTimerWithTimeInterval:0.1 invocation:invocation repeats:NO];
}
Tracking the problem based on the error messsage:
It means that
[[self class] instanceMethodSignatureForSelector:selector];returnednilfor theshowUIAlertView:title:selector. And why? Because your class simply doesn’t implement a message corresponding to the selector – you’re confusing labels and argument names in your method declaration:should in fact be
Also, setting the target to
selfis fine –targetis the object on which you want to call the selector/invocation.