0

我在 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 添加到广告下方的行中。这可能吗?

4

1 回答 1

0

我有一个 ListObject 类,它将存储有关该单元格的数据(例如,标题、缩略图、描述等),所以我添加了一个字段:BOOL isAd然后添加一个新的 ListObject 与isAd = YES每 10 个对象并确保我的单元格创建和高度逻辑知道如何处理广告单元。这样,您的表格中的每个广告视图都有一个列表数据对象。

于 2011-07-07T15:52:10.430 回答