Question

I get one problem is that,

This's showads function.

[self.mMainView addSubview:adViewController.view];
//...(my function to display ads)

This's hideads function.

 //...(my function to hide ads)
 [[AdViewController sharedAdViewController].view removeFromSuperview];
 [self.mMainView setNeedsDisplay];

The mMainView is a UIView. The AdViewController is a UIViewController.

The problems is that after calling showads fucntion, the my ads display on mMainView. But after calling hideads function, the my ads don't disappear, it still appear on mMainView.

Note: After calling hideads and make an interrupt then resume the app, the my ads will disappear.

So, i want to remove it, could you please explain a bit in more detail and show me how to fix it if you can pls ?

Was it helpful?

Solution

You don't need to call setNeedsDisplay when removing or adding subviews. The fact that it updates after an interrupt makes me suspect that you're not calling [[AdViewController sharedAdViewController].view removeFromSuperview]; on the main thread. What is the context of that code?

If it's not on the main thread, you can schedule on it:

dispatch_async(dispatch_get_main_queue(), ^{
   [[AdViewController sharedAdViewController].view removeFromSuperview];
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top