OGeek|极客世界-中国程序员成长平台

标题: ios - 如何刷新 UIView [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 09:35
标题: ios - 如何刷新 UIView

我有一个问题是,

这是 showads 函数。

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

这是 hideads 函数。

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

mMainView 是一个UIViewAdViewControllerUIViewController

问题是调用showads函数后,我的广告显示在mMainView上。但是调用hideads函数后,我的广告并没有消失,它仍然出现在mMainView上。

注意:调用 hideads 并中断然后恢复应用后,我的广告将消失。

所以,我想删除它,请您详细解释一下,如果可以的话,请告诉我如何修复它?



Best Answer-推荐答案


删除或添加 subview 时无需调用 setNeedsDisplay。它在中断后更新的事实使我怀疑您没有在 main 线程上调用 [[AdViewController sharedAdViewController].view removeFromSuperview]; 。该代码的上下文是什么?

如果不在主线程上,可以在上面调度:

dispatch_async(dispatch_get_main_queue(), ^{
   [[AdViewController sharedAdViewController].view removeFromSuperview];
});

关于ios - 如何刷新 UIView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23369549/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4