Jump to content


Forumul s-a mutat!

Aceasta este arhiva forumului MacForum.ro din perioada 2010-2014.
Noul forum poate fi accesat aici.
Conturile vechi nu mai sunt valabile pe noul forum!

Photo

ADBannerView in UINavigation's RootController


  • Please log in to reply
2 replies to this topic

#1 boboc

boboc

    Veteran

  • Membri
  • PipPipPipPip
  • 668 posts
  • Locationvalcea

Posted 26 March 2011 - 20:10

Am si eu o mica/mare problema.
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;
}

Attached Images

  • 1.png
  • 2.png
  • 3.png
  • 4.png
  • 5.png
  • 6.png

Edited by boboc, 26 March 2011 - 20:17.


#2 MacLover

MacLover

    Membru nou

  • Membri
  • Pip
  • 5 posts

Posted 28 March 2011 - 22:05

Problema este in metoda - (void)dealloc;
[adBanner removeFromSuperView];

Rezolvare: in RootController ar trebui sa apelezi in metoda - (void)viewWillAppear:(BOOL)animated;
[self.view addSubview:addBanner]; fara sa apelezi [addBanner removeFromSuperView];

ceva in genul acesta.


PS: s'ar putea sa ma insel.

Edited by MacLover, 28 March 2011 - 22:08.


#3 boboc

boboc

    Veteran

  • Membri
  • PipPipPipPip
  • 668 posts
  • Locationvalcea

Posted 28 March 2011 - 22:44

Mersi pentru raspuns,am rezolvat intre timp.
In viewWillAppear trebuie apelat [self createADBanner]; iar in root banerul este nil deoarece in momentul cand este adaugat ca subview in inboxController superview-ul lui devine inboxcontroller.view.
Cum orice view poate avea doar un superview banerul va disparea din rootcontroller :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users