これは、ストーリーボードで作成されたタブ バー コントローラーについて didFinishLaunchingWithOptions に伝える方法です。メインタブに iAd バナーが表示されるようになりました。しかし、他のタブをタップしても何も起こりません。didSelectViewController が呼び出されることはありません。didSelectViewController を TabBarController に接続し、現在の/アクティブなタブに currentController プロパティを割り当てるにはどうすればよいですか?
#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;
}