In short, the following code raises an existing selector in a superclass, and then throws an NSInvalidException:
- (void)applicationWillResignActive:(UIApplication *)application { if ([super respondsToSelector:@selector(applicationWillResignActive:)]) { [super applicationWillResignActive:application]; }
This gives the following log exception:
- *** Application termination due to an unannounced exception "NSInvalidArgumentException", reason: '- [aAppDelegate applicationDidEnterBackground:]: unrecognized selector sent to instance 0x5b5d360'
To develop ... I have a delegate of the base application (from our new corporate library) declared as:
I have a delegation class of the BaseAppDelegate base application. 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 I mean that I did not specifically write code for this method. It cannot be found in the .h or .m file.
In my application, there is an application 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 application starts, I get the debug output "*** ACTIVE ****" - as it should be.
When I send my application to the background, I get this NSInvalidArgumentException, which indicates that the responder does not exist - and it does not exist, so this is the correct exception for throw.
What do I need to know because WHY answer ToSelector gives YES when I expect to see NO? What is the little subtle thing I'm missing?