I want to catch an event when someone switches between tabs. I have the following two functions in the appdelegate file:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UITabBarController * uitbc = [storyboard instantiateViewControllerWithIdentifier:@"tabbarcontroller"];
uitbc.delegate = self;
[self.window addSubview:uitbc.view];
return YES;
}
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
NSLog(@"switching");
}
But it NSLog(@"switching");never works. Xcode issues a warning for a line uitbc.delegate = self;that says: "Passing appdelegate const__strong to an incompatible type identifier parameter."
What am I doing wrong? I just follow the accepted answer found here, except that I create my ad bar with the tabbarcontroller form:
how to get an event that switches the tab menu on iphone
Update
Based on the skram suggestions, I wrote this for my application, but NSLOG (Switching) still fails:
@interface johnAppDelegate : UIResponder <UITabBarControllerDelegate>
I also updated my didFinishLauchingWithOptions:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
tabBarController = self.window.rootViewController.tabBarController;
tabBarController.delegate = self;
[window addSubview:tabBarController.view];
}
, . . , didSelectViewController .