使用Singleton类实现iAd [英] Implementing iAd using Singleton Class

查看:104
本文介绍了使用Singleton类实现iAd的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是iPhone开发的新手。我的目标是为iAd实现一个单例类,以便在多个视图控制器上共享iAd的单个实例?

I am new to iPhone development. My objective is to implement a singleton class for iAd, so that I share the single instance of iAd over multiple view controllers?

对实施方面的任何帮助都会非常感激吗?

Any help on the implementation side will be much appreciated?

推荐答案

在你的AppDelegate.h中

In your AppDelegate.h

@property (assign) YouiAdClass*iADObject    
+ (AppDelegate*) sharedApplication;
+ (YouriAdClass*)sharedAd

在你的AppDelegate.m

In your AppDelegate.m

@synthesize iADObject

+ (AppDelegate*) sharedApplication
{
    return [[UIApplication sharedApplication] delegate];
}

+(YouriAdClass*)sharedAd
{
    if(iAdObject==nil){
          iADObject=[YouriAdClass new]
   }
   return iADObject;
}

现在,当您想要在任何地方获取对象时,只需调用

Now when you want to get your object in any place just call

YouriADClass*iadObject=[[AppDelegate sharedApplication] sharedAd];

你将获得相同的指针。
请记住在头文件中导入AppDelegate和YouriADClass。

And you will get always the same pointer. Remember to import AppDelegate andYouriADClass in your header files.

这篇关于使用Singleton类实现iAd的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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