我想构建像其他视图一样扩展GADBannerView
的自定义类,但是它不起作用
class ListAd:GADBannerView {
var controller: UIViewController?
convenience init(hostView: UIView, controller: UIViewController) {
self.init(frame: hostView.bounds)
self.autoresizingMask = [.flexibleWidth, .flexibleHeight]
self.translatesAutoresizingMaskIntoConstraints = false
self.controller = controller
hostView.addSubview(self)
}
func loadAd() {
if APP.displayBannerAd {
self.adUnitID = ADMOBIDS["banner"]
self.rootViewController = controller
self.load(GADRequest())
}
}
}
然后我将其初始化
admobBanner = ListAd(hostView: self.view, controller: self)
admobBanner?.loadAd()
得到错误:
[App.ListAd setAdUnitID:]: unrecognized selector sent to instance 0x7fe7f9c04d60'
答案 0 :(得分:0)
尝试致电init(adSize: GADAdSize, origin: CGPoint)
或init(adSize: GADAdSize)
而不是self.init(frame:)