iPhone 中的 Admob 与 Tabbar 和 TableView

发布于 2024-08-24 03:33:32 字数 2408 浏览 6 评论 0原文

我的标签栏有 5 个按钮。在 5 个选项卡中,有 2 个是表格视图,它使用导航控制器在单击单元格时显示子视图。 在标签栏上方,在每个视图中我都为使用“Admob”的广告留出了一些空间。 我正在使用 IB 添加广告。 但当它达到“adMobAd = [AdMobView requestAdWithDelegate:self];”时,它会给出 EXC_BAD_ACCESS在 AdViewController.m 中,

我使用以下代码行将视图添加到选项卡栏视图。在我的代码中,我只是将广告添加到最新新闻中。有人可以帮我解决这个问题吗?

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]; 

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]; 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

假情假意假温柔 2024-08-31 03:33:32

EXC_BAD_ACCESS 可能是因为控制器中的广告视图设置为 nil。

检查您是否已将 Interface Builder 中的 AdMob 视图附加到视图控制器中的视图属性。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文