New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Native Ads #1
Comments
Assuming I understood your intentions I'd probably go with something like this: import CollectionViewMultiColumnLayout
enum Section {
case items([Item])
case ads([Ad])
var numberOfItems: Int {
switch self {
case items(let items): return items.count
case ads(let ads): return ads.count
}
}
var numberOfColumns: Int {
return self.numberOfItems
}
}
class CollectionViewController: UICollectionViewController {
enum ReuseIdentifier {
static let itemCell: String = "itemCell"
static let adCell: String = "adCell"
}
static let numberOfItemColumns: Int = 2
static let numberOfAdColumns: Int = 1
let sections: [Section] = …
override func viewDidLoad() {
super.viewDidLoad()
let layout = CollectionViewMultiColumnLayout()
collectionView.setCollectionViewLayout(layout, animated: false)
}
override func numberOfSections(in collectionView: UICollectionView) -> Int {
return self.sections.count
}
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return self.sections[section].numberOfItems
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let section = self.sections[indexPath.section]
let cell: UICollectionViewCell
switch section {
case .items(let items):
let item = items[indexPath.row]
cell = collectionView.dequeueReusableCell(
withReuseIdentifier: ReuseIdentifier.itemCell,
for: indexPath
)
// prepare `cell` for `item`
case .ads(let ads):
let ad = ads[indexPath.row]
cell = collectionView.dequeueReusableCell(
withReuseIdentifier: ReuseIdentifier.adCell,
for: indexPath
)
// prepare `cell` for `ad`
}
return cell
}
}
extension CollectionViewController: CollectionViewMultiColumnLayoutDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfColumnsInSection section: Int) -> Int {
return self.sections[section].numberOfItems
}
func collectionView(_ collectionView: UICollectionView, columnForItemAt indexPath: NSIndexPath) -> Int? {
// Row-major order:
switch self.sections[indexPath.section] {
case .items(_):
return indexPath.row % CollectionViewController.numberOfItemColumns
case .ads(_):
return indexPath.row % CollectionViewController.numberOfAdColumns
}
}
} |
Thank you so much for email. But MoPub not allow me to pass data framework does itself.
Is it possible to check my code?
https://github.com/3rsin3rgul/test
Thanks in advance
Ersin Ergul
… On 12 Oct 2018, at 12:00, Vincent Esche ***@***.***> wrote:
Assuming I understood your intentions I'd probably go with something like this:
import CollectionViewMultiColumnLayout
enum Section {
case items([Item])
case ads([Ad])
var numberOfItems: Int {
switch self {
case items(let items): return items.count
case ads(let ads): return ads.count
}
}
var numberOfColumns: Int {
return self.numberOfItems
}
}
class CollectionViewController: UICollectionViewController {
enum ReuseIdentifier {
static let itemCell: String = "itemCell"
static let adCell: String = "adCell"
}
static let numberOfItemColumns: Int = 2
static let numberOfAdColumns: Int = 1
let sections: [Section] = …
override func viewDidLoad() {
super.viewDidLoad()
let layout = CollectionViewMultiColumnLayout()
collectionView.setCollectionViewLayout(layout, animated: false)
}
override func numberOfSections(in collectionView: UICollectionView) -> Int {
return self.sections.count
}
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return self.sections[section].numberOfItems
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let section = self.sections[indexPath.section]
let cell: UICollectionViewCell
switch section {
case .items(let items):
let item = items[indexPath.row]
cell = collectionView.dequeueReusableCell(
withReuseIdentifier: ReuseIdentifier.itemCell,
for: indexPath
)
// prepare `cell` for `item`
case .ads(let ads):
let ad = ads[indexPath.row]
cell = collectionView.dequeueReusableCell(
withReuseIdentifier: ReuseIdentifier.adCell,
for: indexPath
)
// prepare `cell` for `ad`
}
return cell
}
}
extension CollectionViewController: CollectionViewMultiColumnLayoutDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfColumnsInSection section: Int) -> Int {
return self.sections[section].numberOfItems
}
func collectionView(_ collectionView: UICollectionView, columnForItemAt indexPath: NSIndexPath) -> Int? {
// Row-major order:
switch self.sections[indexPath.section] {
case .items(_):
return indexPath.row % CollectionViewController.numberOfItemColumns
case .ads(_):
return indexPath.row % CollectionViewController.numberOfAdColumns
}
}
}
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub <#1 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AYMy0GKgB_dEFW5a24hbHJVDzSDMFmPEks5ukGgsgaJpZM4XXI75>.
|
In that case you'll basically have to either:
I'm not experienced with MoPub and somewhat busy right now, sry. :/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,
I have a native ads and i want to return 1 column , other items will be return 2. But i couldnt do it.
Can you help me about this? My ads repeating itself in every 9 item.
Those are my codes
The text was updated successfully, but these errors were encountered: