Admob ads not appear in footer of UITableView when keyboard is shown(显示键盘时,Admob 广告不会出现在 UITableView 的页脚中)
问题描述
I use this to show Admob ads on the footer of UITableView:
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
GADBannerView *sampleView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
sampleView.hidden=true;
}
sampleView.adUnitID = @"myID";
sampleView.rootViewController = self;
[sampleView loadRequest:[GADRequest request]];
return sampleView;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return 50.0;
}
I do not have real iPhone device, so I only test it on simulators. The above code works if the software keyboard is hidden and I typed the word using my MacBook keyboard. However, when I open the software keyboard in simulator, the ads failed to load at footer. Instead it loads directed below the searching bar. How should I solve this? I don't know if this bug also occurred in the real device.
I need a higher rep to comment but the issue might be related to how you create the GADBannerView.
As you know the delegate -tableView:viewForFooterInSection:
is called whenever the footer view needs to be rendered. If you where to scroll this view out of screen and back the delegate will trigger again.
Creating the GADBannerView in the -tableView:viewForFooterInSection:
delegate method will result in a new ad view being created every time you scroll back and forth and a new ad request will be sent.
My suggestion is to move the GADBannerView creation to the -viewDidLoad:
method of the ViewController and return the same instance every time.
@interface MyViewController ()
@property (nonatomic, strong) GADBannerView *footerAdView;
@property (nonatomic, assign, getter=isFooterAdRequested) BOOL footerAdRequested;
@end
@implementation MyViewController
...
-(void)viewDidLoad:(BOOL)animated {
self.footerAdView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];
_footerAdView.adUnitID = @"myID";
_footerAdView.rootViewController = self;
}
...
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
if(![self isFooterAdFetched]) {
[_footerAdView loadRequest:[GADRequest request]];
self.footerAdRequested = YES; // Set this to NO again when ad is dismissed/closed/ended so that a new ad can be requested only when the current one is done.
}
return _footerAdView;
}
...
@end
Even if my vague guess below does not help you, maybe the example helps you retain the same ad view and be a bit nicer to the user by not changing the ad every time the user scrolls back and forth.
My vague guess:
I have never worked with Google Ads so I cannot tell you if they try to handle ads without being properly attached to the view hierarchy. My suspicion was that the detached ad (covered by the keyboard so that a new one is loaded) somehow gets misplaced.
这篇关于显示键盘时,Admob 广告不会出现在 UITableView 的页脚中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:显示键盘时,Admob 广告不会出现在 UITableView 的页脚中


基础教程推荐
- 如何从 logcat 中删除旧数据? 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01