views:

635

answers:

1

Hello,

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

A: 

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
temp.tag will not work because temp is the instance of ViewController class and does not have tag as its property.
pratik
Declare it in the .h file then.
Tom Irving
@Tom: Sorry I am not getting your last comment...plz can you explain in some detail
pratik
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
@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
Try setting a tag on "temp.view" then.
Tom Irving