表格视图中每五个单元格之后的广告单元格 [英] Ad cell after every five cells in tableview

查看:62
本文介绍了表格视图中每五个单元格之后的广告单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在表格视图中,我需要在每五个新闻单元之后添加一个仅包含图片的广告单元.

I need add an ad cell with only image after every five news cells in table view.

如果我要在广告单元格中添加第二部分,则会在所有新闻单元格之后显示一个广告单元格.如果在 indexPath.row == 4 时添加广告单元,则由于 cell.details = news [indexPath.row] ,我的第五个新闻单元将不会出现.

If I will add second section for ad cells, an ad cell will be shown after all news cells. If I will add an ad cell when indexPath.row == 4, my fifth news cell won't appear because of cell.details = news[indexPath.row].

任何建议我该怎么做?谢谢.

Any suggestions how can I do that? Thanks.

推荐答案

在UITableViewDataSource的cellForRowAtIndexPath方法中,下一步:

In the method cellForRowAtIndexPath of UITableViewDataSource do next:

if (indexPath.row % 5 == 0) {
// configure ad cell
} else {
// configure usual cell with news[indexPath.row - (indexPath.row / 5)]
}

这篇关于表格视图中每五个单元格之后的广告单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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