从超级视图中删除当前视图 [英] Remove current view from superview
问题描述
假设我有一个视图控制器"ViewBViewController".在该viewcontroller中,我创建"ViewAViewController"的实例,并使用addSubView:方法显示此ViewAViewController.然后,它处理大量信息,然后完成.我希望它在完成后自动作为子视图被删除.
Let's say I have a viewcontroller "ViewBViewController". In that viewcontroller I create an instance of the "ViewAViewController" and use the addSubView: method to display this ViewAViewController. It then processes a bunch of information, and is now done. I want it to automatically get removed as a subview when it's done.
我正在查看removeFromSuperview方法,但似乎无法从我要删除其视图的viewcontroller中调用它(我的第一个直觉是[self.view removeFromSuperview],但这摆脱了整个问题视图,而不仅仅是我所关注的子视图.
I was looking at the removeFromSuperview method, but can't seem to call that from within the viewcontroller whose view I'm trying to remove (my first instinct was [self.view removeFromSuperview], but that gets rid of the entire view, not just the subview I'm after).
我唯一想到的方法是设置委托协议,并让View B代表View A作为其委托来负责View A的卸载.但是,这种方法似乎有点过大.我想念一个更简单的解决方案吗?
The only way I can think of is setting up a delegate protocol, and have View B take care of the unloading of View A on behalf of View A as its delegate. However this approach seems a bit overkill. Am I missing an easier solution?
提前谢谢!
推荐答案
您是否尝试过:setHidden: YES
吗?
这篇关于从超级视图中删除当前视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!