我想构建像其他 View 一样扩展 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:]:无法识别的选择器发送到实例 0x7fe7f9c04d60'
最佳答案
尝试调用 init(adSize: GADAdSize, origin: CGPoint)
或 init(adSize: GADAdSize)
而不是 self.init(frame:)
关于Swift - 从 GADBannerView 扩展后出现无法识别的选择器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56037578/