如何为iAd创建全局引用并在多个Viewcontrollers中实现 [英] How to create a global reference for iAd and implement in multiple Viewcontrollers
问题描述
我每个都有5个ViewControllers,我必须显示iAd,所以我必须在每个ViewControllers中实现iAd代码。而不是如果我在AppDelegate中创建公共代码集意味着我只需要在需要iAd显示的地方调用该代码。
I'm having 5 ViewControllers in each of that i have to display iAd,so that i have to implement iAd code in each ViewControllers. Instead of that if i create set of common code in AppDelegate means i can just call that code wherever i need iAd to be displayed.
如果有人实施了这个iAd概念意味着帮助我摆脱这个问题。在此先感谢。
If anyone has implemented this iAd concept means help me to get out of this issue. Thanks in Advance.
推荐答案
只需在APP委托中创建一个指向iAD的指针。
Just create a Pointer to iAD in APP delegate.
.h:
@property (strong, nonatomic) ADBannerView *UIiAD;
.m:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
UIiAD = [[ADBannerView alloc] init];
return YES;
}
然后在你的ViewControllers中执行以下操作:
Then in your ViewControllers do this:
.h:
@property (strong, nonatomic) ADBannerView *UIiAD;
.m:
- (AppDelegate *) appdelegate {
return (AppDelegate *)[[UIApplication sharedApplication] delegate];
}
- (void) viewWillAppear:(BOOL)animated {
UIiAD = [[self appdelegate] UIiAD];
UIiAD.delegate=self;
// CODE to correct the layout
}
- (void) viewWillDisappear:(BOOL)animated{
UIiAD.delegate=nil;
UIiAD=nil;
[UIiAD removeFromSuperview];
}
为所有视图控制器执行此操作,并使用适当的代码重新设计布局!
Do this for all the view controllers with appropriate code to redesign the layout!
这篇关于如何为iAd创建全局引用并在多个Viewcontrollers中实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!