I am looking to add an ad cell at the 0 index as well as at after every three cells thereafter. I was successful to add the first one, but uncertain how to approach this.
Both ads just take a single image.
My current code is as follows:
var adCount = 1
var newsTitleArray : [String] = ["News1"]
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return newsTitleArray.count + adCount
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.row == 0 {
let cell = tableView.dequeueReusableCell(withIdentifier: "BannerTableViewCell") as! BannerTableViewCell
cell.adImageView.image = UIImage(named:"Logo")
NewsTableView.rowHeight = 50
return cell
} else {
let cell = tableView.dequeueReusableCell(withIdentifier: "NewsTableViewCell") as! NewsTableViewCell
cell.newsTitle.text = newsTitleArray[indexPath.row - 1]
cell.newsSubTitle.text = newsSubTitleArray[indexPath.row - 1]
cell.newsDate.text = newsDateArray[indexPath.row - 1]
cell.newsImageView.image = UIImage(named: randomPicArray[indexPath.row - 1])
cell.selectionStyle = .none
NewsTableView.rowHeight = 500
return cell
}
}