我试图从 myMethod 调用 showUIAlertView 但得到一个异常:由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“+ [NSInvocation invocationWithMethodSignature:]:方法签名参数不能为 nil”另外,请告知要写什么作为 setTarget 的参数在“[invocation setTarget:self];”行中,我写了 self,因为这两种方法都在同一个文件中。谢谢!!
- (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];
}