1

I have integrated AdMob in my iPhone application.

I am adding an Ad view in of my UIViewController as follows:

ProgrammaticAdViewController *temp = [[ProgrammaticAdViewController alloc] init];
temp = [[ProgrammaticAdViewController alloc] initWithNibName:nil bundle:nil];
[self.view addSubview:temp.view];

So, I will be able to see an Ad view on top of my UIViewController.

Now I have two problems:

  1. I am not able to tap on certain buttons of my UIViewController on which I have added the Ad View. So, for temporary purpose I adding the Ad view as:

    [self.view insertSubView:temp.view atIndex:1];
    
  2. I want to remove the Ad view after sometime so I am using:

    [temp.view removeFromSuperView];
    

But my Ad view is not being removed.

Please help me.

Regards, Pratik

Madhup Singh Yadav
  • 8,110
  • 7
  • 51
  • 84
pratik
  • 4,419
  • 8
  • 41
  • 65

1 Answers1

0

You're creating a memory leak here:

ProgrammaticAdViewController *temp = [[ProgrammaticAdViewController alloc] init];
temp = [[ProgrammaticAdViewController alloc] initWithNibName:nil bundle:nil];

Pick one, don't use both.

You could then set a 'tag' for "temp":

temp.tag = 123;

Then when you want to remove it use:

[[self.view viewWithTag:123] removeFromSuperview];

Hope that helps

Tom Irving
  • 10,041
  • 6
  • 47
  • 63
  • temp.tag will not work because temp is the instance of ViewController class and does not have tag as its property. – pratik Mar 02 '10 at 07:24
  • Declare it in the .h file then. – Tom Irving Mar 02 '10 at 16:35
  • @Tom: Sorry I am not getting your last comment...plz can you explain in some detail – pratik Mar 04 '10 at 04:58
  • Sorry, should have been clearer! Declare "temp" in the .h file of the class you using it in, then you can access it anywhere in the class file. – Tom Irving Mar 04 '10 at 14:02
  • @Tom: I think your misunderstanding...its not the case of accessing "temp", I am saying that temp is the object of type ViewController class and objects of ViewController does not have "tag" property. "tag" property is for objects of UIView class. – pratik Mar 05 '10 at 04:50
  • Try setting a tag on "temp.view" then. – Tom Irving Mar 05 '10 at 20:20