In short, the following code calls an existing selector in the super class, and then gives an NSInvalidException:
- (void)applicationWillResignActive:(UIApplication *)application {
if ([super respondsToSelector:@selector(applicationWillResignActive:)])
{
[super applicationWillResignActive:application];
}
This gives the following log exception:
- *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[aAppDelegate applicationDidEnterBackground:]: unrecognized selector sent to instance 0x5b5d360'
To elaborate... I have a base application delegate (from our new company library) declared as:
I have a base application delegate class, BaseAppDelegate. It is declared as:
@interface CoAppDelegate : NSObject <UIApplicationDelegate>
It implements:
- (void)applicationDidBecomeActive:(UIApplication *)application
{
DebugLog(@"*** ACTIVE ****");
}
It does not implement @selector(applicationWillResignActive:) - or at least what I mean is that I have not specifically written out code for that method. It can't be found in the .h or .m file.
My app has an app delegate that inherits from CoAppDelegate as:
@interface aAppDelegate : CoAppDelegate <UIApplicationDelegate>
I implement both of the above methods as:
- (void)applicationWillResignActive:(UIApplication *)application {
if ([super respondsToSelector:@selector(applicationWillResignActive:)])
{
[super applicationWillResignActive:application];
}
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
if ([super respondsToSelector:@selector(applicationDidBecomeActive:)])
{
[super applicationDidBecomeActive:application];
}
}
When the app launches, I get the debug output "*** ACTIVE ****" - as it should.
When I send my app to the background I get that NSInvalidArgumentException stating that the responder does not exist - and it does not exist, so this is the correct exception to throw.
What I need to know is WHY does respondsToSelector give a YES when I am expecting to see a NO? What is the little subtle thing that I am missing?
Instead of
[super class]
you should use[self superclass]
: