ADBannerNavigation 弹出视图控制器时广告应在的空白区域

发布于 2024-11-24 09:48:53 字数 559 浏览 6 评论 0原文

我下载了 iAdSuite 并查看了 ADBannerNavigation。

在内部,我将 RootViewController 更改为 TextViewController 的子类,以便利用 iAd 横幅调整大小的优势。我也想在 RootView 上显示广告。

现在是 RootViewController.h:

#import <UIKit/UIKit.h>
#import "TextViewController.h"

@interface RootViewController : TextViewController

@end

其他一切都一样。当我编译并运行时,RootView中没有广告出现,当我点击TextView时,广告突然出现。

当我单击返回时,RootView 中现在有空白区域。

为什么? 如何删除空白区域?

I downloaded iAdSuite and looked into ADBannerNavigation.

Inside, I changed the RootViewController to subclass TextViewController in order to take advantage of the iAd banner resizing. I want to display ads on the RootView as well.

This is now RootViewController.h:

#import <UIKit/UIKit.h>
#import "TextViewController.h"

@interface RootViewController : TextViewController

@end

Everything else is the same. When I compile and run, no ads show up in RootView, and when I click into TextView, ads suddenly show up.

When I click to go back, there is now white space in RootView.

WHY?
How do you remove the white space?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南风几经秋 2024-12-01 09:48:53

发现我删除 ADBannerView 的方式存在错误。

iAd Suite 告诉我们:

注意:如果您的应用程序有多个显示 iAd 横幅的选项卡或视图,请确保在每个视图中共享一个 ADBannerView 实例。然后,在用户导航到新视图之前,将共享实例的委托属性设置为 nil,将其从旧视图层次结构中删除,然后将相同的实例添加到打开的视图并将其委托设置为适当的视图控制器。 “AdBannerNavigation”示例展示了这种技术。

因此,在我的 iADBannerView.m 中,我有:

- (void)viewWillDisappear:(BOOL)animated{
  [self removeADBannerFromView];
  [super viewWillDisappear:animated];
}

- (void)removeADBannerFromView{
  NSLog(@"ad removed from view");
  ADBannerView *adBanner = SharedAdBannerView;
  adBanner.delegate = nil;
  [adBanner removeFromSuperview];
 }

- (void)dealloc{
    // we are being called here when we navigate away from this view controller,
// so go ahead and reset our AdBannerView for the next time
//


ADBannerView *adBanner = SharedAdBannerView;
adBanner.delegate = nil;
[adBanner removeFromSuperview];

[contentView release]; contentView = nil;

    [super dealloc];
 }

通过设置断点,我看到通过退出视图,在 view1 上调用 viewWillDisappear,然后在 view0 上调用 viewWillAppear,然后在 view1 上调用 dealloc。

问题是 view1 已经从视图中删除了 ADBannerView,因此 [adBanner removeFromSuperView] 正在从 view0 中删除广告。

通过从 dealloc 方法中删除有问题的代码解决了问题。

Found the error in how I was removing the ADBannerView.

iAd Suite tells us to:

Note: If your application has multiple tabs or views displaying an iAd banner, be sure to share a single instance of ADBannerView across each view. Then, before your users navigate to a new view, set the shared instance’s delegate property to nil, remove it from the old view hierarchy, then add the same instance to the opening view and set its delegate to the appropriate view controller. The "AdBannerNavigation" sample shows this technique.

So, in my iADBannerView.m, I have:

- (void)viewWillDisappear:(BOOL)animated{
  [self removeADBannerFromView];
  [super viewWillDisappear:animated];
}

- (void)removeADBannerFromView{
  NSLog(@"ad removed from view");
  ADBannerView *adBanner = SharedAdBannerView;
  adBanner.delegate = nil;
  [adBanner removeFromSuperview];
 }

- (void)dealloc{
    // we are being called here when we navigate away from this view controller,
// so go ahead and reset our AdBannerView for the next time
//


ADBannerView *adBanner = SharedAdBannerView;
adBanner.delegate = nil;
[adBanner removeFromSuperview];

[contentView release]; contentView = nil;

    [super dealloc];
 }

By setting breakpoints, I saw that by exiting a view, viewWillDisappear was being called on view1, then viewWillAppear on view0 and then dealloc on view1.

The problem was that view1 already removed the ADBannerView from the view, so [adBanner removeFromSuperView] was removing the Ad from view0.

Problem solved by removing offending code from the dealloc method.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文