Remove UIView from UIWindow

I have UIViewController, whose view is added to mine UIWindow. However, if I delete the view, I cannot click anything below where it was. My code is below:

-(void)createFullAd{
    UIViewController *viewController = [UIViewController new];
    self.fullAd = [MobclixFullScreenAdViewController new];
    self.fullAd.delegate = self;
    [self.fullAd requestAndDisplayAdFromViewController:viewController];
    viewController.view.tag = 999999;
    [[[[UIApplication sharedApplication] delegate]window] addSubview:viewController.view];
}

- (void)fullScreenAdViewControllerDidDismissAd:(MobclixFullScreenAdViewController*)fullScreenAdViewController{
    NSLog(@"Dismissed");
    [[[[[UIApplication sharedApplication] delegate] window] viewWithTag:999999]removeFromSuperview];

}
+3
source share
3 answers

@dasblinkenlight gave me an idea for this, if he comes back, I will give him an answer.

It's dirty, but this is the only thing that worked:

-(void)displayAd {
    self.fullAd = [MobclixFullScreenAdViewController new];
    self.fullAd.delegate = self;
    self.adController = [UIViewController new];
    [self.fullAd requestAndDisplayAdFromViewController:self.adController];
    [[[[UIApplication sharedApplication] delegate]window] addSubview:self.adController.view];
}
- (void)fullScreenAdViewControllerDidDismissAd:(MobclixFullScreenAdViewController*)fullScreenAdViewController{
    [fullScreenAdViewController.view removeFromSuperview];
    [[[[UIApplication sharedApplication] delegate]window] setNeedsLayout];
    self.adController = nil;

}

setNeedsLayout is the key, but I called it in the window, not in the adController add-in.

+1
source

I think this is not a correct hierarchy of views. If your target is iOS 5.0+, I think you should use[viewController1 addChildViewController:viewController2]

0
source

May try the following:

-(void)fullScreenAdViewControllerDidDismissAd(MobclixFullScreenAdViewController*)fullScreenAdViewController
{
    NSLog(@"Dismissed");
    [fullScreenAdViewController.view removeFromSuperview];
}
0
source

All Articles