开发者

iPhone Admob UITableView troubles

I am sure this is a simple fix, but I can't seem to find it. I have a table view that currently works just fine, set up as:

static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}


NSUInteger row = [indexPath row];
cell.textLabel.text = [creedsList objectAtIndex:row];
cell.imageView.image = [UIImage imageNamed:[c开发者_JS百科reedsImages objectAtIndex:row]];

return cell;

The Admob SDK says to add this line:

[cell.contentView addSubview:[AdMobView requestAdWithDelegate:self]];

But then it populates EVERY cell with ads. Any thoughts?

EDIT: I am using this code to populate:

NSUInteger row = [indexPath row];
cell.textLabel.text = [creedsList objectAtIndex:row];


You want to do that on only the particular rows you want the ads to show up in.

So if you wanted to show up only on the first row, you could do something like

static int adTag = 999; // Used for identifying whether cell already contains ad
UIView * adView = [cell.contentView viewWithTag:adTag];

if(row == 0 && !adView)
{   
    adView = [AdMobView requestAdWithDelegate:self];
    adView.tag = adTag;
    [cell.contentView addSubview:adView];    
}
else if(row != 0 && adView)
{
    // Must remove since cells are reused.
    [adView removeFromSuperview];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜