Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7537675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:54:56+00:00 2026-05-30T06:54:56+00:00

I am currently doing the following in my code avoid the issue of obscured

  • 0

I am currently doing the following in my code avoid the issue of “obscured” ad. But is it a good practice? One potential problem is that – assume before the viewWillDisappear, there was an ad request send out, and then when the ad come back the adBannerView instance has gone. Would that be a big problem? Should I only do hideAdBanner instead?

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear: animated]; 

    // create the ad banner view
    [self createAdBannerView];

    if (adBannerView != nil) {
       UIInterfaceOrientation orientation = self.interfaceOrientation;
       [self changeBannerOrientation:orientation];
    }
} 

- (void)viewWillDisappear:(BOOL)animated { 
    [super viewWillDisappear:animated]; 

    // iAd
    if (adBannerView != nil) {
        [self hideAdBanner];
        adBannerView.delegate = nil;
        [adBannerView release];
        adBannerView = nil;
    }
} 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T06:54:57+00:00Added an answer on May 30, 2026 at 6:54 am

    I use a singleton for an ad banner and call it into view on each ViewDidLoad. This automatically removes it from the previous view.

    This is for adWhirl, but you should be able to adopt it for just iAD.

    adWhirlSingleton.h

    #import <Foundation/Foundation.h>
    #import "AdWhirlDelegateProtocol.h"
    #import "AdWhirlView.h"
    
    @interface adWhirlSingleton : NSObject <AdWhirlDelegate> {
        AdWhirlView *awView;
        UIViewController *displayVC;
    
    }
    
    @property (strong, nonatomic) AdWhirlView *awView;
    @property (strong, nonatomic) UIViewController *displayVC;
    +(id)sharedAdSingleton;
    -(void)adjustAdSize:(CGFloat)x:(CGFloat)y;
    
    @end
    

    adWhirlSingleton.m

    #import "adWhirlSingleton.h"
    
    @implementation adWhirlSingleton
    static adWhirlSingleton* _sharedAdSingleton = nil;
    @synthesize awView, displayVC;
    
    +(id)sharedAdSingleton
    {
        @synchronized(self)
        {
            if(!_sharedAdSingleton)
                _sharedAdSingleton = [[self alloc] init];
            return _sharedAdSingleton;
        }
        return nil;
    }
    
    +(id)alloc
    {
        @synchronized([adWhirlSingleton class])
        {
            NSAssert(_sharedAdSingleton == nil, @"Attempted to allocate a second instance of a singleton.");
                     _sharedAdSingleton = [super alloc];
                     return _sharedAdSingleton;
        }
    
        return nil;
    }
    
    -(id)init
    {
        self = [super init];
        if (self != nil) {
            // initialize stuff here
            self.awView = [AdWhirlView requestAdWhirlViewWithDelegate:self];
        }
        return self;
    }
    
    -(void)dealloc
    {
        displayVC = nil;
        if (awView) {
            [awView removeFromSuperview]; //Remove ad view from superview
            [awView replaceBannerViewWith:nil];
            [awView ignoreNewAdRequests]; // Tell adwhirl to stop requesting ads
            [awView setDelegate:nil];
            awView = nil;
        }
    }
    
    -(void)adjustAdSize:(CGFloat)x :(CGFloat)y
    {
        [UIView beginAnimations:@"AdResize" context:nil];
        [UIView setAnimationDuration:0.7];
        awView.frame = CGRectMake(x, y, kAdWhirlViewWidth, kAdWhirlViewHeight);
        [UIView commitAnimations];
        NSLog(@"Recent Network Name: %@",[awView mostRecentNetworkName]);
    }
    
    -(BOOL)adWhirlTestMode
    {
        return YES;
    }
    
    -(NSString *)adWhirlApplicationKey
    {
        return @"xxxxxxxxxxxxx";
    }
    
    -(UIViewController *)viewControllerForPresentingModalView
    {
        return displayVC;
    }
    
    -(void)adWhirlDidReceiveAd:(AdWhirlView *)adWhirlView
    {
        NSLog(@"%s",__FUNCTION__);
        NSLog(@"Recent Network Name: %@",[awView mostRecentNetworkName]);
        //[self adjustAdSize];
    }
    
    -(void)adWhirlDidFailToReceiveAd:(AdWhirlView *)adWhirlView usingBackup:(BOOL)yesOrNo
    {
        NSLog(@"%s",__FUNCTION__);
    }
    
    @end
    

    Then import adWhirlSingleton into each ViewController and in each viewWillAppear i just implement this:

    adWhirlSingleton *adWhirlSingle = [adWhirlSingleton sharedAdSingleton];
            adWhirlSingle.displayVC = self;
            [adWhirlSingle adjustAdSize:0 :self.view.frame.size.height -50];
            [self.view addSubview:adWhirlSingle.awView];
            [self.view bringSubviewToFront:adWhirlSingle.awView];
            NSLog(@"Ad Banner View");
    

    but the view I have with a UITableView, I use this:

    adWhirlSingleton *adWhirlSingle = [adWhirlSingleton sharedAdSingleton];
        adWhirlSingle.displayVC = self;
        [adWhirlSingle adjustAdSize:0 :self.tabBarController.view.frame.size.height -99];
        [self.tabBarController.view addSubview:adWhirlSingle.awView];
        NSLog(@"Should have added Ad!");
    

    Hope that helps you a bit

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently doing a code review and the following code made me jump.
Currently I have the following code for a project that represents some probability trees
I'm currently doing the following to give my javascript code a namespace: (function(foo, $,
In C#, currently i'm doing the following code to filter out a specific set
I'm currently doing the following to use typed datasets in vs2008: Right click on
I'm currently doing the following as part of my iPhone application NSArray *paths =
I'm currently doing something like this in some code I'm working on right now:
I am currently using the following code in the AppDelegate to make a UIBarButtonItem
I currently have the following code: <form action=process.php method=POST> <fieldset class=form-search> <input type=text class=input-text
I am currently using the following code and wondering if there is a more

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.