【发布时间】:2020-12-20 00:20:36
【问题描述】:
我希望在 0 索引处以及之后每三个单元格之后添加一个广告单元格。我成功添加了第一个,但不确定如何处理。
两个广告只拍摄一张图片。
我目前的代码如下:
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
}
}
【问题讨论】:
标签: ios swift xcode uitableview indexpath