Ios 显示键盘时,Admob广告不会出现在UITableView的页脚中
我使用此选项在UITableView的页脚上显示Admob广告:Ios 显示键盘时,Admob广告不会出现在UITableView的页脚中,ios,objective-c,iphone,uitableview,admob,Ios,Objective C,Iphone,Uitableview,Admob,我使用此选项在UITableView的页脚上显示Admob广告: - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { GADBannerView *sampleView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner]; if (UI_USER_INTERFACE_IDIOM() ==
- (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;
}
我没有真正的iPhone设备,所以我只在模拟器上测试它。如果软件键盘处于隐藏状态,并且我使用MacBook键盘键入了单词,则上述代码可以正常工作。然而,当我在模拟器中打开软件键盘时,广告无法在页脚加载。相反,它直接加载到搜索栏下方。我应该如何解决这个问题?我不知道这个错误是否也发生在真实的设备上
我需要更高级别的代表发表评论,但问题可能与您如何创建GadbanerView有关 正如您所知,每当需要呈现页脚视图时,都会调用委托
-tableView:viewForFooterInstation:
。如果您要将此视图从屏幕中滚动到何处并返回,代理将再次触发
在-tableView:viewForFooterInstitution:
委托方法中创建GADBanerView将导致每次来回滚动时创建新的广告视图,并发送新的广告请求
我的建议是将GADBannerView创建移动到ViewController的-viewDidLoad:
方法,并每次返回相同的实例
@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
即使我在下面模糊的猜测对你没有帮助,也许这个例子可以帮助你保持相同的广告视图,并且在用户每次来回滚动时不改变广告,从而对用户更友好一些
我模糊的猜测:
我从未使用过谷歌广告,因此我无法告诉你他们是否试图在没有正确连接到视图层次结构的情况下处理广告。我的怀疑是,分离的广告(被键盘覆盖,以便加载新广告)不知何故放错了位置。Tq。这解决了重复发送ad请求的问题。但是广告仍然无法在页脚处加载,也无法直接在搜索栏下方加载。嗯,您是否尝试过使用类似“两个矩形(一个水平,一个垂直)相互重叠”的按钮调试视图层次结构(与暂停按钮一起运行时,您可以在Xcode的下栏中找到它)看看你能不能知道发生了什么?