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

前端 未结 3 600
花落未央
花落未央 2021-01-12 19:23

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

3条回答
  •  自闭症患者
    2021-01-12 19:54

    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!

提交回复
热议问题