Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6758301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:46:04+00:00 2026-05-26T13:46:04+00:00

I am following the Google AdMob Ads iOS tutorial to get Ads working. Everything

  • 0

I am following the Google AdMob Ads iOS tutorial to get Ads working.
Everything works well until i try to add Ads to a UITableView.
My design was to have two sections on a Table where the Ad would appear on the first section and the table data on the second section. This however does not work too well as i get the ad in the first section BUT it is also repeated every 10th cell. I only want the Ad once. How do i do this.

Here is my code…

- (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;
}

Produces this..

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T13:46:04+00:00Added an answer on May 26, 2026 at 1:46 pm

    In cellForRowAtIndexPath:, you need to give the cell with the ad a different cell identifier when you dequeue old cells for reuse. Cells with different subview contents need to have different identifiers, otherwise it will simply pop off the cell that contains the adView whenever it is dequeuing cells from the stack for the Cell identifier.

    Basically, when the ad cell moves offscreen, it is put in the reuse queue and is subsequently popped off and reused for a normal cell when the normal cell at the opposite end of the table view comes into view from offscreen.

    When indexPath.row == 0 (for each section), you’ll need to dequeue the ad cell instead of a normal cell, like so:

    // 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;
    }
    

    Also, check out an open-source library I wrote to manage both iAds and (fallback) AdMob ads with a single line of code. I haven’t tested it with this particular config, but it may help nonetheless.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying the following code http://code.google.com/apis/ajax/playground/#change_the_playing_video It works well when runned from the playground
so recently ive rebuilt my site following Google's AJAX Crawling methods. Everything works fine
Following A well earned retirement for the SOAP Search API from Google announcing they
I have the following google chart code that im working with as an example:
I made a test a program which uses Google maps following a tutorial. I
I am working with SEO PHP scripts and I am just following Google SEO
I receive ads in the following code. When the ad is Google Sense ,
I am using google admob in my application. I have the following code: GADRequest
I'm working on an app that needs to update a google calendar. By following
I am trying to add ads to my Android app using Admob, but have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.