Reputation: 21
In a simple subclass of UIViewController I just implemented a selector as a callback to refresh UI
-(void)afterfollowAction:(id)object{
//blabla
}
but finally I found respondsToSelector can not recognise it. Test code:
SEL callback = @selector(afterFollowAction:);
BOOL test1 = [self respondsToSelector:callback]; //NO
BOOL test2 = [self respondsToSelector:@selector(afterFollowAction:)]; //NO
BOOL test3 = [[self class] instanceMethodForSelector: @selector(afterFollowAction:)]; //YES
BOOL test4 = [self respondsToSelector:@selector(viewWillDisappear:)]; //YES
[self performSelector:callback withObject:nil]; //crash
test2 shows not the local variable callback's issue,
test4 shows it knows it is a UIViewController and self is not nil
test3 shows actually it knows the selector is implemented
but if you invoke it with "performSelector" it throw exception "unrecognized selector"
I searched the web and I did not make error with ":" or nil thing;
I put the declaration of the selector to the header file, but makes no use.
I restarted the Mac and iPhone but it is the same result.
This is a simple class in which I do not re-implement respondsToSelector: selector.
So, Did I make wrong use of respondsToSelector? I just want to make the callback outside this class.
Environment: Mac OS X 10.11.3, Xcode 7.2.1, iOS 9.2.1
Update: find(cmd+F) without match case hide the f/F issue. Thanks to Kiran!
Upvotes: 0
Views: 75
Reputation: 1324
It should be
SEL callback = @selector(afterfollowAction:);
BOOL test1 = [self respondsToSelector:callback]; //NO
BOOL test2 = [self respondsToSelector:@selector(afterfollowAction:)]; //NO
BOOL test3 = [[self class] instanceMethodForSelector: @selector(afterfollowAction:)]; //YES
BOOL test4 = [self respondsToSelector:@selector(viewWillDisappear:)]; //YES
[self performSelector:callback withObject:nil]; //crash
Your are using capital "F"
Upvotes: 1