2011-06-23 35 views
0

我在我的UITableView中实施AdMob时遇到问题。我有一个数组(newsItems),其中包含来自不同网站的新闻提要。该数组按照newsitem的日期排序。我想在tableview中显示newsitems,但在应用程序的免费版本中,我希望AdMob的广告能够在每10个tableviewcell中显示。在UITableView中正确显示adMob或adWhirl广告

我使用的代码从其他答案的广告添加到实现代码如下:

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

回答

0

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