我在第2行之后在TableView中添加AdUnit时遇到问题。我发现有人在另一个question尝试但是我不能在Swift中进行。似乎没有任何东西出现,甚至没有在我的细胞中突破以显示第二细胞上发生了某些事情。非常感谢任何帮助。
var nativeExpressAdView: GADNativeExpressAdView!
let request = GADRequest()
override func viewDidLoad() {
super.viewDidLoad()
nativeExpressAdView.adUnitID = “{adUnitIDNumber}”
nativeExpressAdView.rootViewController = self
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let post = posts[(indexPath as NSIndexPath).row]
if (0 == (indexPath.row % 2)) {
if let cell = tableView.dequeueReusableCell(withIdentifier: "PostCell") as? FeedPostCell {
cell.contentView.addSubview(nativeExpressAdView!)
nativeExpressAdView.loadRequest(request)
} else {
return FeedPostCell()
}
} else {
if let cell = tableView.dequeueReusableCell(withIdentifier: "PostCell") as? FeedPostCell {
cell.postImg.image = UIImage(named:"placeholderImg")
cell.delegate = self
if let img = feedViewController.imageCache.object(forKey: post.imageUrl as NSString) {
cell.configureCell(post, img: img)
} else {
cell.configureCell(post)
}
return cell
} else {
return FeedPostCell()
}
}
return FeedPostCell()
}