Ios 如何避免使每个viewController都成为adWhirl代理?(是否有AdWhirl设计模式)
背景: 上周我问了一个关于在多个ViewController上使用adWhirl的问题,但不幸的是,我仍然不明白 我采纳了这些建议,现在在每个viewController中使用一个在app delegate中创建的adWhirl实例,但我不知道如何响应viewController中的adWhirl delegate事件(Ios 如何避免使每个viewController都成为adWhirl代理?(是否有AdWhirl设计模式),ios,iad,adwhirl,Ios,Iad,Adwhirl,背景: 上周我问了一个关于在多个ViewController上使用adWhirl的问题,但不幸的是,我仍然不明白 我采纳了这些建议,现在在每个viewController中使用一个在app delegate中创建的adWhirl实例,但我不知道如何响应viewController中的adWhirl delegate事件(adWhirlDidReceiveAd:,adWhirlDidFailToReceiveAd:等)因为应用程序代理不知道哪个viewController当前正在显示其adView
adWhirlDidReceiveAd:,adWhirlDidFailToReceiveAd:
等)因为应用程序代理不知道哪个viewController当前正在显示其adView
因此我感到困惑
这个有设计模式吗?我想一定有。如果可以避免的话,我不想用样板adWhirl委托代码来填充我所有的ViewController
下面是我在每个viewController中得到的内容。我尝试在应用程序代理中设置一个方法,每个视图控制器都可以调用该方法来“注册”,该方法拥有应用程序代理的adView的所有权-认为当代理接收到类似adWhirlDidReceiveAd
的事件时,它可以完成以下工作。这种方法奏效了,但让我觉得我是在重新发明轮子
问题:是否存在跨多个视图控制器使用adWhirl视图的设计模式
- (void)viewDidLoad
{
[super viewDidLoad];
AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
[self.view addSubview:appDelegate.adView];
[self.view bringSubviewToFront:appDelegate.adView];
CGSize adSize = [appDelegate.adView actualAdSize];
CGRect onScreenFrame = appDelegate.adView.frame;
onScreenFrame.size.height = adSize.height; // fit the ad
onScreenFrame.size.width = adSize.width;
onScreenFrame.origin.x = (self.view.frame.size.width - adSize.width)/2; // center
onScreenFrame.origin.y = (self.view.frame.size.height - adSize.height);
appDelegate.adView.frame = onScreenFrame;
}
- (void)viewDidDisappear:(BOOL)animated
{
AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
[appDelegate.adView removeFromSuperview];
}
显而易见的答案是创建一个控制器类,所有视图控制器都将成为该类的子类。那么
AdviewDelegateController : UIViewController
及
然后将所有adview逻辑放在AdviewDeleteGateController中。显而易见的答案是创建一个控制器类,所有视图控制器都将成为该类的子类。那么
AdviewDelegateController : UIViewController
及
然后将所有adview逻辑放入AdviewDeleteGateController