我在 UITableView 中实施 AdMob 时遇到问题。我有一个数组(newsItems),其中包含来自不同网站的新闻提要。该数组按新闻站点的日期排序。我想在 tableview 中显示 newsitems,但在应用程序的免费版本中,我希望 AdMob 的广告在每 10 个 tableviewcell 中显示。
我使用其他答案中的代码将广告添加到 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;
}
我知道这是不正确的。通过使用“[newsItems objectAtIndex:indexPath.row]”,通过遍历数组并将索引处的 newsitem 添加到匹配行来填充表。这意味着如果应将添加添加到第 10 行,则数组第 10 行的相应 newsItem 不会被 AdWhirl-ad 忽略和覆盖。
相反,我希望将该 newsitem 添加到广告下方的行中。这可能吗?