views:

361

answers:

1

I'm having tab bar with 5 buttons. Out of 5 tabs, 2 are table views which uses navigation controller for showing sub views on click of cell. Above the tab bar, in each view I left some space for ads using "Admob". I'm adding ads using IB. But its giving EXC_BAD_ACCESS when its reaching "adMobAd = [AdMobView requestAdWithDelegate:self];" in AdViewController.m

I'm using following lines of code to add views to tab bar view. In my code, I just added ads to LatestNews only. Can some one help me out of this problem.

UINavigationController *localNavigationController;

// create tab bar controller and array to hold the view controllers
tabBarController = [[UITabBarController alloc] init];
NSMutableArray *localControllersArray = [[NSMutableArray alloc] initWithCapacity:5];

// setup the first view controller (Root view controller)
LatestNews* latestNewsController;
latestNewsController = [[LatestNews alloc] initWithTabBar];



 // create the nav controller and add the root view controller as its first view
  localNavigationController = [[UINavigationController alloc] initWithRootViewController:latestNewsController];

  // add the new nav controller (with the root view controller inside it)
  // to the array of controllers
  [localControllersArray addObject:localNavigationController];

  // release since we are done with this for now
  [localNavigationController release];
  [latestNewsController release];

  // setup the second view controller just like the first
  Forums* forumsController;
  forumsController = [[Forums alloc] initWithTabBar];

  localNavigationController = [[UINavigationController alloc] initWithRootViewController:forumsController];
  [localControllersArray addObject:localNavigationController];
  [localNavigationController release];
  [forumsController release];

 RecipeList* recipesController = [[RecipeList alloc] initWithTabBar];
 localNavigationController = [[UINavigationController alloc] initWithRootViewController:recipesController];
 [localControllersArray addObject:localNavigationController];
 [localNavigationController release];
 [recipesController release];

 //Setup Connect view
 Connect* cnt = [[Connect alloc] initWithTabBar];
 [localControllersArray addObject:cnt];
 [cnt release];

 //Setup Subscribe View
 Subscribe* scribe = [[Subscribe alloc] initWithTabBar];
 [localControllersArray addObject:scribe];
 [scribe release];

  // load up our tab bar controller with the view controllers
  tabBarController.viewControllers = localControllersArray;

  [localControllersArray release];
  [window addSubview:tabBarController.view];
  [window makeKeyAndVisible]; 
A: 

The EXC_BAD_ACCESS is likely because the ad view is set to nil in the controller.

Check that you've attached the AdMob view in Interface Builder to a view attribute in your view controller.

NeilInglis