這是我告訴didFinishLaunchingWithOptions有關在故事板中創建的選項卡欄控制器。它現在在主選項卡中顯示iAd標語。但是當我點擊其他標籤時沒有任何反應。 didSelectViewController永遠不會被調用。我如何將didSelectViewController連接到我的TabBarController並將currentController屬性分配給當前/活動選項卡?在AppDelegate didSelectViewController不叫
#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;
}
是的,謝謝,但我仍然沒有迴應didSelectViewController – ingenspor 2012-07-29 23:13:49
你爲什麼這樣編程?如果你正確設置了故事板,那麼你不需要實現「didSelectViewController」。看看[本教程](http://codingandcoffee.wordpress.com/2011/10/12/iphone-tutorial-two-combining-uitabbarcontrollers-uitableviews-and-uinavigationcontrollers/) - 我認爲它可以幫助你。 – Stretch 2012-07-29 23:23:47
謝謝你,我會檢查出來的,但首先它工作正常。也許我不需要didSelectViewController,但我必須告訴iAd關於currentController。我的代碼的任何建議? – ingenspor 2012-07-29 23:36:07