私はUIcollectionView内に広告を追加したいと思います。 4番目のフォルダごとに、広告を表示したい(合計3回、したがって4,9と14行)。UICollection 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)。私はコレクションビューと私のフォルダの中に私の広告を追加する方法はありますか?
ありがとうございます!
tableViewDataSourceの 'numberOfRowsInSection'メソッドに+3を追加する必要があります –
参照[コレクションビュー内に広告を表示する方法](http://stackoverflow.com/q/43062278/643383) – Caleb
@ReinierMelianwishそれは簡単でした。 indexpath.rowでは1つのセルだけを配置しますが、他のセルは配置しません – SoundShock