This is how I tell didFinishLaunchingWithOptions about the Tab Bar Controller created in storyboard. It now displays the iAd banner in the main tab. But nothing happens when I tap the other tabs. didSelectViewController is never being called. How can I connect didSelectViewController to my TabBarController and assign currentController property to current/active tab?
#import "AppDelegate.h"
@interface AppDelegate()
@property (nonatomic, retain) ADBannerView *bannerView;
@property (nonatomic, assign) UIViewController<BannerViewContainer> *currentController;
@end
@implementation AppDelegate
@synthesize window = _window;
@synthesize bannerView;
@synthesize currentController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch
CGRect screenBounds = [[UIScreen mainScreen] bounds];
// bannerView was here
// This is the reference to the tab bar controller and first tab from storyboard.
UITabBarController *tabController = (UITabBarController *)self.window.rootViewController;
self.currentController = [[tabController viewControllers] objectAtIndex:0];
NSLog(@"Root: %@", self.window.rootViewController);
NSLog(@"Tab with banner: %@", self.currentController);
return YES;
}
//and this isn't called:
- (void)tabController:(UITabBarController *)tabController didSelectViewController:
(UIViewController *)viewController
{
// If called for selection of the same tab, do nothing
if (currentController == viewController) {
return;
}
if (bannerView.bannerLoaded) {
// If we have a bannerView atm, tell old view controller to hide and new to show.
[currentController hideBannerView:bannerView];
[(UIViewController<BannerViewContainer>*)viewController showBannerView:bannerView];
}
// And remember this viewcontroller for the future.
self.currentController = (UIViewController<BannerViewContainer> *)viewController;
}