嗨,你可以帮我,我想添加我的滚动视图控制器,但我添加它,但它显示在我的桌子上:(在swift
这是我的代码
var dataModel: DataModel!
var bannerView = ADBannerView()
override func viewDidLoad() {
super.viewDidLoad()
tableView.rowHeight = 60
tableView.rowHeight = UITableViewAutomaticDimension
//Rate my apps alert codes
var iMinSessions = 20
var iTryAgainSessions = 30
var iNoThanks = 50
var thanksforrate = NSUserDefaults.standardUserDefaults().boolForKey("thanksforrate")
var neverRate = NSUserDefaults.standardUserDefaults().boolForKey("neverRate")
var numLaunches = NSUserDefaults.standardUserDefaults().integerForKey("numLaunches") + 1
if (!neverRate && (numLaunches == iMinSessions || numLaunches >= (iMinSessions + iTryAgainSessions + iNoThanks + 1)))
{
showRateMe()
numLaunches = iMinSessions + 1
numLaunches = iNoThanks + 1
}
NSUserDefaults.standardUserDefaults().setInteger(numLaunches, forKey: "numLaunches")
//BannerView
bannerView = ADBannerView(adType: .Banner)
bannerView.setTranslatesAutoresizingMaskIntoConstraints(false)
bannerView.delegate = self
view.addSubview(bannerView)
let viewsDictionary = \["bannerView": bannerView\]
//view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|\[bannerView\]", options: .allZeros, metrics: nil, views: viewsDictionary))
//view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|\[bannerView\]", options: .allZeros, metrics: nil, views: viewsDictionary))
}
func bannerViewDidLoadAd(banner: ADBannerView!) {
bannerView.hidden = false
}
func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
bannerView.hidden = true
}
答案 0 :(得分:2)
试试这个
func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 50
}
func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
var adView : UIView = UIView(frame: CGRectMake(0, 0, self.view.frame.size.width, 50))
adView.autoresizingMask=UIViewAutoresizing.FlexibleWidth
bannerView = ADBannerView(adType: .Banner)
bannerView.setTranslatesAutoresizingMaskIntoConstraints(false)
bannerView.delegate = self
adView.addSubview(self.bannerView!)
return adView
}
答案 1 :(得分:1)
在viewDidLoad中添加此内容
self.tableView.contentInset = UIEdgeInsets(top:self.bannerView.frame.size.height, left: 0, bottom: 0, right: 0)