在目标C的FooterTableViewCell中放置视图的问题

时间:2018-07-19 18:38:48

标签: ios objective-c uitableview admob

我有一个表格视图,其中有一个页脚视图单元格。我在页脚表视图单元格类中有一个视图。在我的VC类中,我为页脚单元格调用了委托,我将Admob视图传递给该视图,但是没有在上面显示广告。如何在该视图上展示广告?这是我的FooterCell类代码:

@property (weak, nonatomic) IBOutlet GADBannerView *adView;

这是我在VC课堂上获得的视图,

- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    FooterTVCell *footerTVCell = [tableView dequeueReusableCellWithIdentifier:@"FooterTVCell"];
        //Admob Banner
    bannerView_ = [[GADBannerView alloc]initWithFrame:CGRectMake(0, 450, [UIScreen mainScreen].bounds.size.width, 70)];
    bannerView_.adUnitID = @"ca-app-pub-3940256099942544/2934735716"; //change this key
    GADRequest *request = [GADRequest request];
    //request.testDevices = @[ @"326e918015806f8d65a43e86f9e6e939" ];
    request.testDevices = @[ kGADSimulatorID ];
    NSLog(@"%@", request.testDevices);
    bannerView_.rootViewController = self;
    bannerView_.delegate = self;

    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    button.frame = CGRectMake(0, 0, 25, 25);
    // [button setTitle:@"Cancel" forState:(UIControlState)UIControlStateNormal];
    [button setBackgroundImage: [UIImage imageNamed:@"cancel.png"] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(goToFun) forControlEvents:(UIControlEvents)UIControlEventTouchUpInside];
    [bannerView_ addSubview:button];

    [footerTVCell.adView addSubview:bannerView_];
    [bannerView_ loadRequest:request];

    return footerTVCell;
}

这是我运行应用程序时的看法, enter image description here

2 个答案:

答案 0 :(得分:1)

只需检查您提到的y位置即可。

bannerView_ = [[GADBannerView alloc]initWithFrame:CGRectMake(0, **450**, [UIScreen mainScreen].bounds.size.width, 70)];

在Xcode的“调试”视图层次结构工具中进行检查。另外,如果只有一个部分,请在viewDidLoad中将其作为adman视图设置为tableview.footerview。

答案 1 :(得分:0)

我认为您错过了添加Apple documentation所要求的另一个委托。

  

此方法仅在   tableView(_:heightForFooterInSection :)也已实现。

您还需要实现该方法,才能正常工作。