本文介绍了是removeFromSuperview发布对象吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 removeFromSuperview
从其超级视图中删除视图。我也在该对象的 removeFromSuperview
之后使用 release
,有时它的工作正常,但有时会给出错误的访问权限。
I am using removeFromSuperview
for removing a view from its superview. I am also using release
after removeFromSuperview
on that object, sometimes its work fine but sometimes give bad access.
removeFromSuperview
还要调用发布
到对象?
推荐答案
是的, removeFromSuperview
也发布视图。
您需要在将视图添加到超级视图后发布视图。
You need to release your view after you have added it to its superview.
CGRect frame; // let's assume you already have defined frame and superview
UIView *superview;
UIView *subview = [[UIView alloc] initWithFrame:frame];
[superview addSubview:subview];
[subview release];
或者只是在创建时使用 autorelease
一个视图。
Or just use autorelease
, when you create a view.
UIView *subview = [[[UIView alloc] initWithFrame:frame] autorelease];
[superview addSubview:subview];
在这两种情况下,您都不需要致电发布
致电 removeFromSuperview
。
In both cases, you don't need to call release
after you call removeFromSuperview
.
这篇关于是removeFromSuperview发布对象吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!