将AdMob广告放在tableview控制器的底部-Swift [英] Place AdMob ad at the bottom of tableview controller - swift

查看:96
本文介绍了将AdMob广告放在tableview控制器的底部-Swift的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图在swift上实现Admob,但一切都很好,但是我遇到了问题,因为我使用的是自定义表格视图单元格和表格视图控制器作为主要的swift文件,因此当我拖动时将BannerView放到作为表格视图控制器的情节提要中,广告实际上就会出现在表格视图的第一个单元格中!相反,我需要将其加载到tableview控制器的按钮上而不是单元格内部?

I've been trying to implement Admob on swift and everything is good, but i run out of problem because I'm using custom table view cell and "Table view controller" as the main swift file, so when i am dragging the BannerView into the storyboard which is the table view controller, the ad actually appear in the first cell of the table view ! instead i need to load it at the button of the tableview controller not inside the cells ?

@IBOutlet weak var bannerView: GADBannerView!


    override func viewDidLoad() {
        super.viewDidLoad()


        self.bannerView.adUnitID = "ca-app-pub-3940256099942544/2934735716"

        self.bannerView.rootViewController = self

        var request: GADRequest = GADRequest()

        request.testDevices = [GAD_SIMULATOR_ID]

        self.bannerView.loadRequest(request)



        // Uncomment the following line to preserve selection between presentations
        // self.clearsSelectionOnViewWillAppear = false

        // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
        // self.navigationItem.rightBarButtonItem = self.editButtonItem()
    }


推荐答案

一种解决方案是创建 bannerView 的新实例,而不是将其作为出口,然后将其作为子视图添加到tableView的超级视图。

One solution could be to create a new instance of bannerView instead of having it as an outlet and then add it as a subview to the tableView's superview.

这篇关于将AdMob广告放在tableview控制器的底部-Swift的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆