在 UITableView 中正确显示 adMob 或 adWhirl 广告
我在 UITableView 中实现 AdMob 时遇到问题。我有一个数组(newsItems),其中包含来自不同网站的新闻源。该数组按新闻条目的日期排序。我想在表格视图中显示新闻站点,但在应用程序的免费版本中,我希望在每 10 个表格视图单元格中显示来自 AdMob 的广告。
我使用其他答案中的代码将广告添加到表格视图:
if (0 == (row % 10)) {
//cells with an add
static NSString *MyIdentifier;
NSInteger row = [indexPath row];
MyIdentifier = [NSString stringWithFormat:@"AdCell%d", row];
cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];
}
[cell.contentView addSubview:[AdMobView requestAdWithDelegate:self]];
return cell;
} else {
// the code to create a standard cell (simplified)
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
NSString *cellValue = [newsItems objectAtIndex:indexPath.row];
cell.text = cellValue;
}
我知道这是不正确的。通过使用“[newsItems objectAtIndex:indexPath.row]”,通过遍历数组并将索引处的 newsitem 添加到匹配行来填充表。这意味着,如果应将添加添加到第 10 行,则数组第 10 行的相应 newsItem 不会被 AdWhirl-ad 忽略和覆盖。
相反,我希望将该新闻站点添加到广告下方的行中。这可能吗?
I have a problem with implementing AdMob in my UITableView. I have an array (newsItems) that contains news-feeds from different websites. The array is sorted by the date of the newsitem. I want to display the newsitems in a tableview, but in the free version of the app I want an advertisement from AdMob to show in every 10th tableviewcell.
I used the code from an other answer to add the ads to the tableview:
if (0 == (row % 10)) {
//cells with an add
static NSString *MyIdentifier;
NSInteger row = [indexPath row];
MyIdentifier = [NSString stringWithFormat:@"AdCell%d", row];
cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];
}
[cell.contentView addSubview:[AdMobView requestAdWithDelegate:self]];
return cell;
} else {
// the code to create a standard cell (simplified)
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
NSString *cellValue = [newsItems objectAtIndex:indexPath.row];
cell.text = cellValue;
}
I know this is not correct. By using “[newsItems objectAtIndex:indexPath.row]” the table is populated by going through the array and adding the newsitem at the index to the matching row. This means that if an add should be added to row 10, the corresponding newsItem at row 10 of the array is not ignored and overwritten by the AdWhirl-ad.
In stead I want that newsitem to be added to the row beneath the ad. Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我有一个 ListObject 类,它将存储有关该单元格的数据(例如标题、缩略图、描述等),因此我添加了一个字段:
BOOL isAd
,然后只需添加一个带有的新 ListObject isAd = YES 每 10 个对象,并确保我的单元格创建和高度逻辑知道如何处理广告单元格。这样,您的表中的每个广告视图就有一个列表数据对象。
I had a ListObject class which would store the data about that cell (eg. Title, thumbnail, desc etc.) so I added a field:
BOOL isAd
and then just added a new ListObject withisAd = YES
every 10 objects and made sure that my cell creation and height logic knew what to do with Ad cells. This way, you have a list data object for each Ad view in your table.