2011-09-09 3 views
1

나는 광고를 얻으려면 Google AdMob Ads iOS 자습서를 따르고 있습니다. UITableView에 광고를 추가 할 때까지 모든 것이 잘 작동합니다. 제 디자인은 첫 번째 섹션에는 광고가 표시되고 두 번째 섹션에는 테이블 데이터가있는 표에 두 개의 섹션이 있어야합니다. 그러나 이것은 첫 번째 섹션에서 광고를 얻지 만 너무 잘 작동하지 않지만 10 번째 셀마다 반복됩니다. 나는 단지 한 번 광고를 원한다. 어떻게해야합니까? 여기 UITableView GADBannerView

내 코드는

...

- (void)viewDidLoad { 
[super viewDidLoad]; 

UIBarButtonItem *refreshButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refresh:)]; 
self.navigationItem.rightBarButtonItem = refreshButtonItem; 
[refreshButtonItem release]; 

// Create a view of the standard size at the bottom of the screen. 
bannerView_ = [[GADBannerView alloc] 
       initWithFrame:CGRectMake(0.0, 
             0.0, 
             GAD_SIZE_320x50.width, 
             GAD_SIZE_320x50.height)]; 

// Specify the ad's "unit identifier." This is your AdMob Publisher ID. 
bannerView_.adUnitID = @"blablabla"; 

// Let the runtime know which UIViewController to restore after taking 
// the user wherever the ad goes and add it to the view hierarchy. 
bannerView_.rootViewController = self; 
GADRequest *adMobRequest = [GADRequest request]; 

adMobRequest.testDevices = [NSArray arrayWithObjects: 
          GAD_SIMULATOR_ID,        // Simulator 
          @"fafasfasdfasdrasdasfasfaasdsd",         nil]; 

// Initiate a generic request to load it with an ad. 
} 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
// Return the number of sections. 
return 2; 
} 


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
// Return the number of rows in the section. 

if (section == 0) { 
    return 1; 
} else { 
    return 50; 
} 
} 


// Customize the appearance of table view cells. 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"]; 
if (cell == nil) {  
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"Cell"];   
    cell.selectionStyle = UITableViewCellSelectionStyleNone; 

} 

if (indexPath.section == 0) { 
    if (indexPath.row == 0) { 
    [cell addSubview:bannerView_]; 
    } 
} else { 
    cell.textLabel.text = @"Test"; 
    cell.detailTextLabel.text = @"Test"; 
    cell.imageView.image = nil; 
}  

return cell; 
} 

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
return 50; 
} 

은 생산이 ..

enter image description here

+0

사용자가 화면에 표시하기 전에 광고를 작성하여 노출을 보낼 tableviewcell에 추가하기 전에 광고를 요청하고 있습니다.이 광고는 어느 누구도 미친 것으로 간주 될 수 있습니다. –

답변

4

cellForRowAtIndexPath:에서, 당신은 광고에 셀 당신이 큐에서 다른 셀 식별자를 제공해야 재사용을위한 오래된 세포. 다른 하위 뷰 내용이있는 셀은 다른 식별자를 가져야하며, 그렇지 않으면 스택에서 Cell 식별자로 셀을 dequeuing 할 때마다 adView가 포함 된 셀이 튀어 나오게됩니다.

기본적으로 광고 셀이 화면 밖으로 이동하면 재사용 대기열에 저장되고 이후 테이블 뷰의 반대쪽 끝에있는 일반 셀이 화면에서 벗어날 때 일반 셀에 대해 다시 열리고 다시 사용됩니다. 당신과 같이, 정상 세포 대신 광고 셀을 큐에서해야합니다 (각 섹션)

indexPath.row == 0

: 또한

// Customize the appearance of table view cells. 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    NSString *cellId = "Cell"; 
    if(indexPath.row == 0) //first cell in each section 
     cellId = @"ad"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId]; 
    if (cell == nil) {  
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"Cell"];   
     cell.selectionStyle = UITableViewCellSelectionStyleNone; 

     if(indexPath.row == 0) 
      [cell addSubview:bannerView_]; 
    } 


    if (indexPath.row != 0){ 
     cell.textLabel.text = @"Test"; 
     cell.detailTextLabel.text = @"Test"; 
     cell.imageView.image = nil; 
    }  

    return cell; 
} 

open-source library를 체크 아웃은 내가 모두 제군을 관리하기 위해 쓴 한 줄의 코드로 된 (대체) 대체 광고입니다. 그럼에도 불구하고이 특정 구성으로 테스트하지는 못했지만 그럼에도 불구하고 도움이 될 수 있습니다.