将AdWhirl视图添加到tabBarController
问题描述:
我想将Adwhirl视图添加到当前iOS应用程序的顶部。该应用程序由五个不同的视图组成,这些视图都在单个TabBarController的控制下。任何人都可以写一个简短的教程,显示实现此目的所需的代码?我已经浏览并尝试了很多解决方案,但没有一个能够实现它。将AdWhirl视图添加到tabBarController
下面是我目前的尝试在这个问题,我没有得到错误,但我没有看到任何不同的屏幕上。提前致谢。
@implementation idoubs2AppDelegate
@synthesize window;
@synthesize tabBarController;
@synthesize contactsViewController;
@synthesize messagesViewController;
@synthesize adwhirlview = adview;
static UIBackgroundTaskIdentifier sBackgroundTask = UIBackgroundTaskInvalid;
static dispatch_block_t sExpirationHandler = nil;
#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
AdWhirlView *adView = [AdWhirlView requestAdWhirlViewWithDelegate:self];
[self.tabBarController.view addSubview:adView];
adView.center = CGPointMake(160, 342);
[self.tabBarController.view bringSubviewToFront:adView];
}
- (NSString *)adWhirlApplicationKey {
// return your SDK key
return kSampleAppKey;
}
- (UIViewController *)viewControllerForPresentingModalView {
//return UIWindow.viewController;
return [(idoubs2AppDelegate *)[[UIApplication sharedApplication] delegate] tabBarController];
}
- (void)adWhirlDidReceiveAd:(AdWhirlView *)adWhirlView {
}
答
我认为,不要向UITabBar添加子视图,您可以考虑制作类似于GADBannerView
单例的东西,然后您可以将其添加到您的UITabBarController
包含的ViewControllers
中的每一个。
所以你可以很容易地设置一个单例(有另一个StackOverflow问题here,谈论如何做到这一点AdMob广告和使它与AdWhirl工作应该是微不足道的)。
然后,只需添加一些ViewControllers
到您UITabBarController
做这样的事情:
UIViewController *viewController1 = [[[FirstViewController alloc]
initWithNibName:@"FirstViewController"
bundle:nil]
autorelease];
UIViewController *viewController2 = [[[SecondViewController alloc]
initWithNibName:@"SecondViewController"
bundle:nil]
autorelease];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:
viewController1,
viewController2,
nil];