2009-10-18 123 views
5

我试图将AdMob广告添加到表格视图。如何将AdMob广告添加到UITableView

我希望它在每10个细胞中出现。 (例如,如果您拥有它,它就如何在免费版的Reddit应用程序中使用)。

我试图遵循AdMob文档,但我没有任何运气,我确信有一些我错过了。

任何人都可以照亮一些简单的方法来做到这一点? 谢谢!

回答

15

我使用的代码基本上是这样的:

int row = [indexpath row]; 

if (0 == (row % 10)) { // or 9 == if you don't want the first cell to be an ad! 
    static NSString *MyIdentifier = @"AdCell"; 
    cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier]; 

    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease]; 
    } 
    [cell.contentView addSubview:[AdMobView requestAdWithDelegate:self]]; 
} else { 
    // make your normal cells 
} 
+1

绝对的传奇! 非常感谢,这真的很有帮助。 – JordanC 2009-10-18 02:40:49

+1

这确实很好,除了所显示的广告都是一样的。第一个或第二个是独一无二的,那之后,ReusableCell系统开始投入使用,您将获得再生广告。我是这样做的: static NSString * MyIdentifier; NSInteger row = [indexpath row]; MyIdentifier = [NSString stringWithFormat:@“AdCell%d”,row]; – Mikepote 2011-03-31 08:44:27

+2

数据源返回计数如何? – itsji10dra 2016-08-30 15:35:23

相关问题