我有一个视图控制器,它查询网络服务是否应该显示插页式广告。如果是这样,则使用 presentViewController:animated:completion: 实例化和呈现另一个视图控制器。根据这个答案和文档,我假设 viewDidAppear: 在关闭呈现的视图控制器(它自己做)时不会被调用。从概念上讲,无论如何对我来说,呈现视图控制器的视图永远不会从视图层次结构中删除,因此永远不需要“重新出现”。我显然错了。那么发生了什么?为什么我看到的与文档所说的不同?
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[[AdService sharedAdService] adForSlotName:@"Main Interstitial" completionBlock:^(Ad *adForSlotName) {
if(adForSlotName)
{
InterstitialAdViewController_iPhone *interstitialAdViewController = [[InterstitialAdViewController_iPhone alloc] init];
interstitialAdViewController.ad = adForSlotName;
dispatch_queue_t mainQueue = dispatch_get_main_queue();
dispatch_async(mainQueue, ^{
[self presentViewController:interstitialAdViewController animated:YES completion:^{}];
});
[interstitialAdViewController release];
}
}];
}
- (void)viewWillDisappear:(BOOL)animated
{
[[AdService sharedAdService] clearAdForSlotName:@"Main Interstitial"];
[super viewWillDisappear:animated];
}