ADBannerView in UINavigation’s RootController
  [ Ignoră ]
Avatar
RankRankRankRank
Sr. Member
Din: Bucuresti
Macuser din: 22.09.06

Am si eu o mica/mare problema.
Vreau sa folosesc un ADBannerView in root controller-ul unei aplicatii navigasion 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 layoutBannerNO];    
}


- (voidviewWillAppear:(BOOL)animated
{       
    NSLog
(@"viewWillAppear called");
    
    
ADBannerView *theBanner = (ADBannerView *)[self.view viewWithTag1000];
    
NSLog(@"theBanner value: %@",theBanner);
    
    
[self layoutBannerNO];
}


- (voidviewDidUnload
{
    [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.0fCGRectGetMaxY(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
.-= bannerHeight+44;
    
}
    
else
    
{
        bannerOrigin
.+= bannerHeight+44;
    
}

    [UIView animateWithDuration
animationDuration animations:^{
        adBanner
.frame CGRectMake(bannerOrigin.xbannerOrigin.yadBanner.frame.size.widthadBanner.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;
 Semnătură 

A man should look for what is, and not for what he thinks should be.—Albert Einstein

Profil
 
  [ Ignoră ]   [ # 1 ]
Avatar
RankRankRankRank
Sr. Member
Din: Bucuresti
Macuser din: 22.09.06

imaginile 4,5 si 6 sunt urmatoarele smile

 Semnătură 

A man should look for what is, and not for what he thinks should be.—Albert Einstein

Profil
 
  [ Ignoră ]   [ # 2 ]
Avatar
RankRankRank
Member
Din: Bucuresti - Baba Novac
Macuser din: 10.05.06
boboc - 26 Martie 2011 07:16 PM

imaginile 4,5 si 6 sunt urmatoarele smile

Ai grija sa reinitializezi BannerController-ul in momentul in care renunti la view-ul de inbox.

 Semnătură 

cool smirk  Generally a smart-ass!

Profil
 
  [ Ignoră ]   [ # 3 ]
Avatar
RankRankRankRank
Sr. Member
Din: Bucuresti
Macuser din: 22.09.06

Am vazut si eu ca merge totul ok daca apelez in root/viewWillAppear metoda

[self createADBannerView]

Acum intrebarea mea e daca apelez aceasta metoda si in viewDidLoad si in viewWillAppear banner-ul din delegate nu va fi adaugat de 2 ori subview al root.view ???

 Semnătură 

A man should look for what is, and not for what he thinks should be.—Albert Einstein

Profil
 
  [ Ignoră ]   [ # 4 ]
Avatar
RankRankRankRank
Moderator
Din: Cluj-Napoca
Macuser din: 26.01.06

Un view nu poate sa aiba mai multe superviewuri, dar o sa ai leak-uri la adBanner.

 Semnătură 

Mcintoshing…

Profil
 
  [ Ignoră ]   [ # 5 ]
Avatar
RankRankRankRank
Sr. Member
Din: Bucuresti
Macuser din: 22.09.06

@.ral:cr asta nu ar fi o problema,as putea in viewWillDissapear sa apelez [banner removeFromSuperview];
Dar ce se intampla daca incerc sa apelez [self.view addSubview: banner]; cand acesta deja exista ca subview al lui self.view ?

 Semnătură 

A man should look for what is, and not for what he thinks should be.—Albert Einstein

Profil
 
  [ Ignoră ]   [ # 6 ]
Avatar
RankRankRankRank
Moderator
Din: Cluj-Napoca
Macuser din: 26.01.06

O sa-l mute pe un nivel mai sus.
Vezi ca tu creezi doua referinte pt SharedAdBannerView, una in adBanner, si alta pt ca i-ai adaugat un superview.

 Semnătură 

Mcintoshing…

Profil
 
  [ Ignoră ]   [ # 7 ]
Avatar
RankRankRankRank
Sr. Member
Din: Bucuresti
Macuser din: 22.09.06

Asa este si in proiectul iAdSuite/AdBannerNavigation de la Apple:

http://developer.apple.com/library/ios/#samplecode/iAdSuite/Introduction/Intro.html

 Semnătură 

A man should look for what is, and not for what he thinks should be.—Albert Einstein

Profil
 
  [ Ignoră ]   [ # 8 ]
Avatar
RankRankRankRank
Sr. Member
Din: Bucuresti
Macuser din: 22.09.06

Daca era dupa mine fiecare controller avea banner-ul lui si nu mai era nici o problema dar asa recomanda Apple.

 Semnătură 

A man should look for what is, and not for what he thinks should be.—Albert Einstein

Profil
 
  [ Ignoră ]   [ # 9 ]
Avatar
RankRankRankRank
Sr. Member
Din: Bucuresti
Macuser din: 22.09.06

Daca pun in viewWillAppear urmatorul cod merge totul ok:

if([self.view viewWithTag1000] == nil)
    
[self createADBannerView]

Singura faza care nu o inteleg este de ce in rootController baner-ul dispare si in inbox controller nu dispare? Mai ales ca dealloc nu este apelat(verificat cu NSLog) si nici viewDidUnload(aceasta stiu ca se apeleaza automat cand apare un memory warning) deci prin urmare nu se apeleaza metoda

[adBanner removeFromSuperview]
 Semnătură 

A man should look for what is, and not for what he thinks should be.—Albert Einstein

Profil
 
  [ Ignoră ]   [ # 10 ]
Avatar
RankRankRankRank
Sr. Member
Din: Bucuresti
Macuser din: 22.09.06

Ah,aici raspunsul e simplu,cum un view nu poate avea decat un singur superView din cauza asta dispare din rootController smile

 Semnătură 

A man should look for what is, and not for what he thinks should be.—Albert Einstein

Profil
 
   
 
 
‹‹ Xcode 4 si c      xCode ››