Nicholas
Nicholas

Reputation: 1935

iAd banner below tableview

I'm creating an iAd programmatically in my tableview application I did the following in the AppDelegate.swift I wrote

import iAd

than I defined the proper variable

var bannerView: ADBannerView!

and I defined the properties of the banner itself

bannerView = ADBannerView(adType: .Banner)
bannerView.setTranslatesAutoresizingMaskIntoConstraints(false)
bannerView.delegate = self
bannerView.hidden = true

Finally I call in my tableview controller the following

let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
view.addSubview(appDelegate.bannerView)

with the constraints

let viewsDictionary = ["bannerView": appDelegate.bannerView]
view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[bannerView]|", options: .allZeros, metrics: nil, views: viewsDictionary))
view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|[bannerView]", options: NSLayoutFormatOptions.allZeros, metrics: nil, views: viewsDictionary))

However the banner is fixed at the top and while I'm scrolling is disappearing underneath the view. Instead it should be always on top of everything. Furthermore it's covering part of the tableview that is not visible. How can I define that the tableview starts right below the banner or how can I move the banner below the tableview?

Thanks

Upvotes: 3

Views: 312

Answers (1)

Antoine
Antoine

Reputation: 1149

To load the banner on the top, just have a try with this one :

import iAd

class ViewController: UITableViewController, ADBannerViewDelegate {

var adBannerView:ADBannerView?

override func viewDidLoad() {
super.viewDidLoad()

adBannerView = ADBannerView(adType: ADAdType.Banner)
adBannerView?.delegate = self
//Initialize the banner and delegate
}

override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
return adBannerView
}
//With this func the adBannerView is the header of your tableView.

Hope it helps :)

Upvotes: 2

Related Questions