1

I downloaded iAdSuite and looked into ADBannerNavigation.

Inside, I changed the RootViewController to subclass TextViewController in order to take advantage of the iAd banner resizing. I want to display ads on the RootView as well.

This is now RootViewController.h:

#import <UIKit/UIKit.h>
#import "TextViewController.h"

@interface RootViewController : TextViewController

@end

Everything else is the same. When I compile and run, no ads show up in RootView, and when I click into TextView, ads suddenly show up.

When I click to go back, there is now white space in RootView.

WHY? How do you remove the white space?

Jon
  • 7,848
  • 1
  • 40
  • 41

1 Answers1

0

Found the error in how I was removing the ADBannerView.

iAd Suite tells us to:

Note: If your application has multiple tabs or views displaying an iAd banner, be sure to share a single instance of ADBannerView across each view. Then, before your users navigate to a new view, set the shared instance’s delegate property to nil, remove it from the old view hierarchy, then add the same instance to the opening view and set its delegate to the appropriate view controller. The "AdBannerNavigation" sample shows this technique.

So, in my iADBannerView.m, I have:

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

- (void)removeADBannerFromView{
  NSLog(@"ad removed from view");
  ADBannerView *adBanner = SharedAdBannerView;
  adBanner.delegate = nil;
  [adBanner removeFromSuperview];
 }

- (void)dealloc{
    // we are being called here when we navigate away from this view controller,
// so go ahead and reset our AdBannerView for the next time
//


ADBannerView *adBanner = SharedAdBannerView;
adBanner.delegate = nil;
[adBanner removeFromSuperview];

[contentView release]; contentView = nil;

    [super dealloc];
 }

By setting breakpoints, I saw that by exiting a view, viewWillDisappear was being called on view1, then viewWillAppear on view0 and then dealloc on view1.

The problem was that view1 already removed the ADBannerView from the view, so [adBanner removeFromSuperView] was removing the Ad from view0.

Problem solved by removing offending code from the dealloc method.

Jon
  • 7,848
  • 1
  • 40
  • 41