I'm trying to insert totally random ads between cells within a UITableView
. It's more or less what I want:
Sothere'smyTableViewController:
importUIKitimportGoogleMobileAdsclassPage1:UITableViewController,UISearchBarDelegate,GADBannerViewDelegate{.........@IBOutletweakvarGoogleBannerView:GADBannerView!overridefuncviewDidLoad(){super.viewDidLoad()self.searchBar.delegate=selfself.tableView.contentOffset=CGPoint(x:0,y:searchBar.frame.height)//hidesearchBarShared.instance.employees.sort{(first,second)infirst.name.compare(second.name,options:.diacriticInsensitive)==.orderedAscending}}overridefunctableView(_tableView:UITableView,cellForRowAtindexPath:IndexPath)->UITableViewCell{ifindexPath.row==3||indexPath.row==9||indexPath.row==14{letcellAd=tableView.dequeueReusableCell(withIdentifier:"cellAd", for: indexPath)
GoogleBannerView?.adUnitID = "ca-app-pub-6043248661561548/4628935113"
GoogleBannerView?.rootViewController = self
GoogleBannerView?.load(GADRequest())
return cellAd
}
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! TableViewCell1
if isSearching {
cell.nameLabel.text = employeesSearching[indexPath.row].name
cell.positionLabel.text = employeesSearching[indexPath.row].position
} else {
let letter = collation.sectionTitles[indexPath.section]
let matches = getMatches(letter: letter, withArray: Shared.instance.employees)
cell.nameLabel.text = matches[indexPath.row].name
cell.positionLabel.text = matches[indexPath.row].position
}
return cell
}
...
...
...
}
I would like someone to explain to me what I should do in cellForRowAt
for me to add Ads. Because between the indexed sections I'm kind of confused.
EDIT
This is my current TableViewCell class:
import UIKit
class TableViewCell1: UITableViewCell {
@IBOutlet weak var nameLabel: UILabel!
@IBOutlet weak var positionLabel: UILabel!
}