Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a global reference for iAd and implement in multiple Viewcontrollers

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.

If anyone has implemented this iAd concept means help me to get out of this issue. Thanks in Advance.

like image 997
Sudharson Avatar asked May 08 '12 13:05

Sudharson


1 Answers

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

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!

like image 67
João Nunes Avatar answered Sep 20 '22 16:09

João Nunes