I’m getting a EXC_BAD_ACCESS exception when I call performSelector:withObject: from a object that does implement the method I’m trying to call. Here’s my code
SEL newSelector = NSSelectorFromString(@"mySelector:withCustomObject:");
[self performSelector:newSelector withObject:myCustomObject];
This causes a crash. However when I do this
[self performSelector:@selector(mySelector:withCustomObject:) withObject:myCustomObject];
it works.
Any ideas on why this is happening?
PS: none of the parameters are nil.
MORE CODE:
// My code to call this method
SEL newSelector = NSSelectorFromString(@"mySelector:withCustomObject:");
[self performSelector:newSelector withObject:self withObject:myCustomObject];
// this code is NOT called.
- (void) mySelector:(jObject *)sender withCustomObject:(jEvent *)customObject
{
NSDictionary *handlerData = [aProperty objectAtIndex:[event positionInMethodStack]];
NSString *newTitle = [handlerData objectForKey:@"newTitle"];
}
"mySelector:withCustomObject:"is the signature of a method with 2 arguments, such asBut you call
performSelector:withObject:, which sends a message with only one argument tomySelector. The second argument is undefined, which probably causes the crash.So if
mySelectoractually has 2 arguments, useperformSelector:withObject:withObject:, otherwise fix the signature of the selector.