【发布时间】:2011-04-11 02:25:15
【问题描述】:
我正在向我的应用添加 iAd,但它崩溃了,因为在视图发布后调用了 AdBannerView 委托。我正在关注 Apple 文档中的代码示例,以及我在 Apple Dev 论坛上找到的代码示例,但我遗漏了一些东西,因为它崩溃了。
我在要在其中显示的视图的 viewDidLoad 中创建 AdBannerView...
self.bannerIsVisible = NO;
self.adView = [[ADBannerView alloc] initWithFrame:CGRectMake(0, 0, 1024, 66)];
adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifierLandscape];
adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
adView.delegate = self;
[self.view addSubview:adView];
我把它放在 viewDidAppear 的前面...
[self.view bringSubviewToFront:[self adView]];
adView.frame = CGRectMake(0.0, 0.0, adView.frame.size.width, adView.frame.size.height);
我在 viewDidUnload 中将它设置为 nil...
[[self adView] setDelegate:nil];
[self setAdView:nil];
然后我在 dealloc 中释放它...
[adView release];
然而,应用程序时不时会因此错误而崩溃...
-[MyViewController bannerView:didFailToReceiveAdWithError:]: message sent to deallocated instance 0xf61d820
我错过了什么?
非常感谢您的智慧!
【问题讨论】: