所有 ViewController 中的 AdMod 单个实例 [英] AdMod single instance in all ViewControllers

查看:17
本文介绍了所有 ViewController 中的 AdMod 单个实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的应用程序中使用 AdMob,并且我有 4 个视图控制器(在 4 个选项卡项中)我想让它可见.示例显示的方式,每个 ViewController 都需要创建它的实例并添加为子视图.

I want to use AdMob in my app and I have 4 viewControllers (in 4 tab items) where I want to make it visible. The way the sample shows, every ViewController needs to make instance of it and add as subview.

我仍在考虑是否可以通过某种方式仅使用 1 个可在所有应用程序中使用的实例.我怎样才能做到这一点?

I am still thinking if there can be someway to use only 1 instance that can be used in all application. How can I do that?

如果我在 AppDelegate 中创建 1 个实例作为 autorelease 并在每个 viewController 中保留并在 viewDidUnload 上释放它,然后在下一个选项卡项 (viewController) 中再次保留它等...这是好方法吗?

If I create 1 instance in AppDelegate as autorelease and retain in each viewController and on viewDidUnload release it and then in next tab item (viewController) i again retain it etc...is it good approach?

推荐答案

AppDelegate 方法是一个不错的方法,但您不应该在每个视图控制器中保留 admob 的实例并在 viewDidUnload 中释放相同的实例 方法.而不是这样做,只需在每个视图控制器的 viewDidLoad 方法中添加 admob 的视图作为子视图.这样一来,AppDelegate 中将只有一个 Admob 视图实例.

The AppDelegate aproach is a nice approach but you should not retain the instance of the admob in every viewcontroller and release the same in the viewDidUnload method. Instead of doing this just add the admob's view in every viewcontroller's viewDidLoad method as a subview. In this manner there will be only one instance of the Admob's view in the AppDelegate.

希望对你有所帮助.

这篇关于所有 ViewController 中的 AdMod 单个实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆