Vreau sa folosesc un ADBannerView in root controller-ul unei aplicatii navigation based.
Am luat proiectul iAdSample de la Apple iar acolo se recomanda ca banner-ul sa fie pus in app delegate,lucru facut si de mine.
Aplicatia mea are un root controller si inca 5 custom controlere (Inbox,Today,Scheduled,Someday si Logbook).
Implementarea folosita atat in root controller cat si in celelalte controlere este aceasi,ce-a atasata.
Problema mea este urmatoarea:
Cand aplicatia porneste prima data,root controller-ul afisaza banner-ul corect.
Daca selectez orice sectiune,ex Inbox se apeleaza didSelectRowAtIndexPath: iar Inbox Controller este afisat,iar aici banner-ul este tot ok.
Problema apare cand ma intorc in root controller,baner-ul nu mai apare,am verificat cu NSLog si banner-ul este nil. (vedeti imaginile 1,2 si 3).
Partea ce-a mai ciudata este ca,daca fac acelasi lucru din Inbox controller selectand un rand, se apeleaza didSelectRowAtIndexPath iar Edit task controller este afisat iar cand ma intorc inapoi in Inbox controller baner-ul apare si nu este nil ca in root Controller,lucru verificat din nou cu NSLog. (vedeti imaginile 4,5 si 6).
#define SharedAdBannerView ((myAppDelegate *)[[UIApplication sharedApplication] delegate]).adBanner - (void)viewDidLoad { [super viewDidLoad]; NSLog(@"viewDidLoad called"); [self createADBannerView]; [self layoutBanner: NO]; } - (void) viewWillAppear:(BOOL)animated { NSLog(@"viewWillAppear called"); ADBannerView *theBanner = (ADBannerView *)[self.view viewWithTag: 1000]; NSLog(@"theBanner value: %@",theBanner); [self layoutBanner: NO]; } - (void) viewDidUnload { [super viewDidUnload]; ADBannerView *adBanner = SharedAdBannerView; adBanner.delegate = nil; [adBanner removeFromSuperview]; } - (void)dealloc { ADBannerView *adBanner = SharedAdBannerView; adBanner.delegate = nil; [adBanner removeFromSuperview]; [super dealloc]; } #pragma mark - #pragma mark ADBanner Methods - (void)createADBannerView { ADBannerView *adBanner = SharedAdBannerView; NSString *contentSize = ADBannerContentSizeIdentifierPortrait; CGRect frame; frame.size = [ADBannerView sizeFromBannerContentSizeIdentifier:contentSize]; frame.origin = CGPointMake(0.0f, CGRectGetMaxY(self.view.bounds)); adBanner.frame = frame; adBanner.delegate = self; adBanner.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin; adBanner.requiredContentSizeIdentifiers = [NSSet setWithObjects:ADBannerContentSizeIdentifierPortrait,nil]; // added a tag to check with NSLog in the viewWillAppear method if the banner is nil when i pop back adBanner.tag = 1000; [self.view addSubview:adBanner]; } - (void)layoutBanner:(BOOL)animated { ADBannerView *adBanner = SharedAdBannerView; CGFloat animationDuration = animated ? 0.5f : 0.0f; adBanner.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait; CGPoint bannerOrigin = CGPointMake(CGRectGetMinX(self.view.bounds), CGRectGetMaxY(self.view.bounds)); CGFloat bannerHeight = adBanner.bounds.size.height; if (adBanner.bannerLoaded) { bannerOrigin.y -= bannerHeight+44; } else { bannerOrigin.y += bannerHeight+44; } [UIView animateWithDuration: animationDuration animations:^{ adBanner.frame = CGRectMake(bannerOrigin.x, bannerOrigin.y, adBanner.frame.size.width, adBanner.frame.size.height); }]; } - (void)bannerViewDidLoadAd:(ADBannerView *)banner { NSLog(@"bannerViewDidLoadAd called"); [self layoutBanner:YES]; } - (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error { NSLog(@"didFailToReceiveAdWithError called"); [self layoutBanner:YES]; } - (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave { return YES; }
Edited by boboc, 26 March 2011 - 20:17.