我正在使用 removeFromSuperview
从其 super View 中删除 View 。我还在该对象上的 removeFromSuperview
之后使用 release
,有时它工作正常,但有时访问权限很差。
removeFromSuperview
是否也对对象调用 release
?
最佳答案
是的,removeFromSuperview
也会释放 View 。
将 View 添加到其 super View 后,您需要释放它。
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];
或者在创建 View 时使用autorelease
。
UIView *subview = [[[UIView alloc] initWithFrame:frame] autorelease];
[superview addSubview:subview];
在这两种情况下,您都不需要在调用 removeFromSuperview
后调用 release
。
关于iphone - 是removeFromSuperview释放了对象吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8366380/