IAd banner below the table
I am creating iAd programmatically in my tableview application I did the following in AppDelegate.swift
, I wrote
import iAd
than I defined the correct 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 the following in my tableview controller
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
view.addSubview(appDelegate.bannerView)
with restrictions
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 as I scroll, it disappears below the view. Instead, he should always be at the top of everything. In addition, it covers the part of the table that is not visible. How can I determine that the table view starts right below the banner or how can I move the banner below the table?
thank
+3
source to share
1 answer
To load the banner from above, just try with this:
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 this helps :)
+2
source to share