Swift: iAd position of UITableViewController

I created an iAd banner in storyboard by dragging and dropping it into UITableViewController

In mine UITableViewController

I have these codes

@IBOutlet var adBannerView: ADBannerView!

      

IN ViewDidLoad

self.canDisplayBannerAds = true
self.adBannerView.delegate = self
self.adBannerView.hidden = true

      

And this delegate method

func bannerViewActionShouldBegin(banner: ADBannerView!, willLeaveApplication willLeave: Bool) -> Bool {
    return true
}

func bannerViewDidLoadAd(banner: ADBannerView!) {
    self.adBannerView.hidden = false
}

func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
    println("didFailToReceiveAdWithError")
    self.adBannerView.hidden = true
}

      

Sometimes when UITableViewLoads it will look like

http://i.stack.imgur.com/P4p1J.png

iAd will be at the bottom of the TableView and will move with it

However, sometimes it just loads at the bottom of the fixed position window that I want.

How do I get the iAd to be fixed to the bottom and not move with the table view?

+3


source to share


3 answers


Your problem is that you are actually creating two ADBannerView

here. Once in Interface Builder and once in viewDidLoad

p self.canDisplayBannerAds = true

. Uninstall self.canDisplayBannerAds = true

from viewDidLoad

to fix this.

To link your ADBannerView

created in Interface Builder to the bottom of your application, you need to set its constraints. Connect ADBannerView

to the bottom of the view with Bottom Space to: Bottom Layout Guide

and align with Align Center X to: Superview

in the Interface Builder.



This will keep ADBannerView

the bottom of your app and resize it accordingly if on devices with different screen sizes.

+3


source


I was unable to add any constraints to the storyboard. I removed the iAd banner from the storyboard and just used:

self.canDisplayBannerAds = true

      



It works fine now

0


source


I had a similar problem, so I just coded it by hand. Nothing worked when my code was in ViewDidLoad, but instead ViewWillAppear all I needed was

override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)

    self.canDisplayBannerAds = true
    self.banner.delegate = self
}

      

And of course add ADBannerViewDelegate at the beginning of the class, and then its methods:

let banner = ADBannerView(adType: .Banner)

func bannerViewDidLoadAd(banner: ADBannerView!) {
    self.view.addSubview(banner)
}

func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
    banner.removeFromSuperview()
}

      

-1


source







All Articles