所以我想在我的UIcollectionView中添加广告。每隔4个文件夹后,我想显示一个广告(总共3次,因此第4,9和14行)。UICollectionView不同的单元格每个x单元格
我已经试过如下:
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if indexPath.row == 4 || indexPath.row == 9 || indexPath.row == 14 {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "AdUnitsCollectionViewCell", for: indexPath) as? AdUnitsCollectionViewCell
//cell?.addSubview(AdUnitController().getBannerView(2))
//cell?.view = AdUnitController().getBannerView(2)
cell?.view.adUnitID = "/6499/example/banner"
cell?.view.rootViewController = self
cell?.view.load(DFPRequest())
return cell!
} else {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: FolderViewCellIdentifier, for: indexPath) as? FolderViewCell
cell!.configure(folders![indexPath.row])
return cell!
}
}
但这3次的确展示广告的每4个文件夹后,但现在我为indexPath.row文件夹不再显示(4,9和14)。有没有一种方法可以将我的广告添加到collectionview和我的文件夹中?
谢谢!
您需要在您的tableViewDataSource –
又见你的'numberOfRowsInSection'方法添加+3 [如何集合视图中显示广告(http://stackoverflow.com/q/43062278/643383) – Caleb
@ReinierMelianwish就这么简单。给我一个索引是越界(必须小于187)',因为在indexpath.row我只放置一个单元格,但不是其他 – SoundShock