2009-10-18 122 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

相關問題