Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 8th, 2012  |  syntax: None  |  size: 1.90 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. didSelectViewController in AppDelegate is not called
  2. #import "AppDelegate.h"
  3.  
  4. @interface AppDelegate()
  5.  
  6. @property (nonatomic, retain) ADBannerView *bannerView;
  7. @property (nonatomic, assign) UIViewController<BannerViewContainer> *currentController;
  8.  
  9. @end
  10.  
  11. @implementation AppDelegate
  12.  
  13. @synthesize window = _window;
  14. @synthesize bannerView;
  15. @synthesize currentController;
  16.  
  17. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  18. {
  19.     // Override point for customization after application launch
  20.  
  21.     CGRect screenBounds = [[UIScreen mainScreen] bounds];
  22.  
  23.     // bannerView was here
  24.  
  25.     // This is the reference to the tab bar controller and first tab from storyboard.
  26.     UITabBarController *tabController = (UITabBarController *)self.window.rootViewController;
  27.     self.currentController = [[tabController viewControllers] objectAtIndex:0];
  28.  
  29.     NSLog(@"Root: %@", self.window.rootViewController);
  30.     NSLog(@"Tab with banner: %@", self.currentController);
  31.  
  32.     return YES;
  33. }
  34.  
  35. //and this isn't called:
  36.  
  37. - (void)tabController:(UITabBarController *)tabController didSelectViewController:
  38. (UIViewController *)viewController
  39. {
  40.     // If called for selection of the same tab, do nothing
  41.     if (currentController == viewController) {
  42.         return;
  43.         }
  44.     if (bannerView.bannerLoaded)  {
  45.      // If we have a bannerView atm, tell old view controller to hide and new to show.
  46.         [currentController hideBannerView:bannerView];
  47.         [(UIViewController<BannerViewContainer>*)viewController showBannerView:bannerView];
  48.         }
  49.         // And remember this viewcontroller for the future.
  50.     self.currentController = (UIViewController<BannerViewContainer> *)viewController;
  51.  
  52. }
  53.        
  54. // This is the reference to the tab bar controller and first tab from storyboard.
  55. UITabBarController *tabController = (UITabBarController *)self.window.rootViewController;
  56. tabController.delegate = self;