如何在集合视图中显示广告 [英] How to display ads within a collection view

查看:135
本文介绍了如何在集合视图中显示广告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的collectionView中随机添加一些横幅广告。

每个collectionView单元格都是基本图片(黑色方块)这里是为了让事情变得更容易)从数组中动态填充(让我们说它是一个非常长的数组,并称之为longDataArray),我将从网上获得。

Each collectionView cell would be a basic image (black square here to make things easier) populated dynamically from an array (let's say it's a really long array and call it "longDataArray") that I would get from the web.

I可以设法将一些横幅广告添加到我的collectionView,但问题是它打破了我的longDataArray的顺序。
例如,仅在我在indexPath 6添加广告横幅时进行测试,然后广告横幅正确地显示在indexPath 6上,并且我能够管理单元格的宽度变化,我的longDataArray在indexPath 6对应的图像显然永远不会出现。

I could manage to add some banner ads to my collectionView but the problem is that it's breaking the order of my longDataArray. For example, just for testing when I'm adding an ad banner at indexPath 6, then the ad banner correctly shows up at indexPath 6, and I'm able to manage the width change for the cell, but the image corresponding at the indexPath 6 for my longDataArray would obviously never appears.

我也可以将我的longDataArray分成两部分,然后再玩部分:section 0 = firstPartOfArray,section 1 = ad banner,section 2 = secondPartOfArray。但这需要花费大量精力创建不同的数组和部分,只需添加一个广告横幅,而且显然不是我想要的。

I also could do it spliting my longDataArray in two, and then playing with the sections : section 0 = firstPartOfArray, section 1 = ad banner, and section 2 = secondPartOfArray. But this takes a lot of effort creating differents arrays and sections, just to add only one ad banner, and it's obviously not what I'm looking for.

所以我的问题是,你如何在collectionView中添加横幅广告(只有一个部分),但保留indexPath逻辑?

我搜索了很多关于那个,我很惊讶我无法解决这个问题。

I googled a lot about that, and was surprised that I could not come up with any solution for this problem.

你们有什么想法吗?

谢谢!

< img src =https://i.stack.imgur.com/Do8pE.pngalt =screenshot>

推荐答案

我们成功为Ersin开发了一个关于这个问题的例子。

We succeeded that developed an example for with Ersin for this issue.

你可以在这里查看。

https://github.com/Cemoo/WaterFlowLayout

这篇关于如何在集合视图中显示广告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆