我有一个UIView
对象,我将其添加为子视图,使用[self.view addSubview:mySubView];
. 之后我打电话
[mySubView removeFromSuperview];
,然后我尝试做,[mySubView release];
但应用程序在这里崩溃。
还RemoveFromSuperview
叫吗release
?mySubView
我有一个UIView
对象,我将其添加为子视图,使用[self.view addSubview:mySubView];
. 之后我打电话
[mySubView removeFromSuperview];
,然后我尝试做,[mySubView release];
但应用程序在这里崩溃。
还RemoveFromSuperview
叫吗release
?mySubView
是removeFromSuperview
的,释放视图。
你检查过文档吗?大约需要 5 秒:
讨论
如果接收者的superview不是nil
,superview释放接收者。如果您打算重用视图,请务必retain
在调用此方法之前使用它,并release
在以后适当时再次使用它。
是的,超级视图保留其所有子视图,因此当您删除视图时,其超级视图将释放它。
请发布您的代码,否则很难回答
崩溃代码
UIView *subview = [[UIView alloc] init]; //manual allocation
[self.view addSubView:subview]; //view retained automatically
[subview release]; //released the manual allocated memory
for(UIView *subview in [scrollView subviews]) {
[subview removeFromSuperview]; //released the view retained automatically. Now retain count reach 0/
[subview release]; // crash.....
}
没有崩溃的代码
UIView *subview = [[UIView alloc] init]; //manual allocation
[self.view addSubView:subview]; //view retained automatically
[subview removeFromSuperview]; //released the view retained automatically. Now retain count reach 1
[subview release]; // No crash .retain count reach 0
你只是不释放你自己没有明确分配或保留的东西。