问题描述
我在self.view中添加了一些按钮.当用户单击一个按钮时,我将加载另一视图(subView).我在其中加载subView的代码如下所示
I have added a few buttons to self.view. When the user clicks on one button, i will load another view (subView). My code where i am loading the subView is shown below
subView = [[UIView alloc] initWithFrame:CGRectMake(0,0,self.scrollView.contentSize.width, self.scrollView.contentSize.height)];
subView.tag=1;
// and then i add various other components to it
[self.view addSubview:subView]; // and finally add it to the view
当用户触摸此视图时,我会检测到该视图并删除该视图(我已经完成了检测部分).
When the user touches this view, i detect it and remove the view (i have already done the detection part).
这就是我删除视图的方式
This is how i am removing the view
UIView *v = [self.subView viewWithTag:1];
v.hidden = YES;
[v endEditing:YES];
[v removeFromSuperview];
该视图消失了,但是我无法单击按钮或self.view上的任何内容.当我将鼠标光标停留在按钮上一会儿时,我可以单击它,否则我无法.我该如何解决?
The view dissapears, but i can't click on the buttons or anything that was on the self.view. When i hold the mouse cursor on a button for awhile i could click it otherwise i can't. How can i solve this ?
推荐答案
我认为您的问题是您这样做
I think your problem is that you do
[self.subView viewWithTag:1];
但是您要删除的视图是self.view所拥有"的,因此它应该是
but the view you want to remove is "owned" by self.view so it should be
[self.view viewWithTag:1];
但是,如果您有对subView的引用,为什么还要再次搜索它?为什么不立即:
But if you have a reference to subView, why search it again? Why not immediately:
self.subView.hidden = YES;
[self.subView endEditing:YES];
[self.subView removeFromSuperview];
您可能想调查一下内存管理,我看到您分配了subView,但是当再次删除该视图时,我看不到它被释放.也许您会这样做,而您只是不显示代码,在这种情况下,请忘记我的评论.
Btw you might want to look into your memory management, I see you alloc your subView but I don't see it being released, when the view is removed again. Maybe you do and you just don't show the code, in that case forget my comment.
这篇关于从其超级视图中删除视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!