Ads and UITableView error

62 views
Skip to first unread message

Fabricio Padua

unread,
Aug 26, 2014, 6:41:57 PM8/26/14
to google-adm...@googlegroups.com
hello Guys!!


but is not work correct, i don't undertend my error. 

The error is that when I print the banner is not jumping one cell, the cell is creating satisfied!

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    int row = [indexPath row];

    GADBannerView *bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeSmartBannerPortrait];

    bannerView_.adUnitID = @"ca-app-pub-xxxxxxx/xxxxxxx";

    bannerView_.rootViewController = self;

    static NSString * CellIndentifier = @"Cell";

    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:CellIndentifier forIndexPath:indexPath];

     if ((row % kFrequencyAdsInCells) == (kFrequencyAdsInCells - 1)) {

        cell = [tableView dequeueReusableCellWithIdentifier:CellIndentifier];

        if (cell == nil) {

            cell = [[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIndentifier];

        }

        if (!bannerView_.superview) {

             [bannerView_ loadRequest:[GADRequest request]];

        }

        [cell.contentView addSubview:bannerView_]; 

    }

    NSManagedObject * Agro = [propriety objectAtIndex:indexPath.row];

    [cell.textLabel setText:[Agro valueForKey:@"namePropriety"]];

    return cell;

}

Eric Leichtenschlag

unread,
Aug 26, 2014, 8:01:24 PM8/26/14
to google-adm...@googlegroups.com
Check out this example for an application of what was mentioned in the blog post. The sample is a little bit different in that it only embeds an ad at the top and bottom of the list.

What I notice is different in your code is that you're dequeueing a cell of type "Cell" even if the spot is for an ad. You probably want two different cell types. You're also setting cell.textLabel even if the spot is for an ad! So the cell is probably just displaying the text regardless of the fact that you're trying to load a banner into it.

Thanks,
Eric
Reply all
Reply to author
Forward
0 new messages