如何释放Views?
我在viewDidLoad中创建视图,例如
UIScrollView* scrollViewright = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0,400,768)];
[scrollViewright setContentSize:CGSizeMake(400,1000)];
[self.view addSubview:scrollViewright];
这样,我怎样才能释放它们?
我使用[scrollViewright发布];在'-(void)dealloc'和'-(void)viewDidUnload'中self.scrollViewright = nil,他们都告诉我错误,所以有人可以帮助我吗?
i create views in viewDidLoad,such as
UIScrollView* scrollViewright = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0,400,768)];
[scrollViewright setContentSize:CGSizeMake(400,1000)];
[self.view addSubview:scrollViewright];
so,how can i release them?
i use [scrollViewright release]; in '- (void)dealloc' and self.scrollViewright = nil in '-(void)viewDidUnload',both of them tell me wrong ,so can anybody help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,您可以执行两种释放:
下一种是当您想从主视图中删除scrollView时:
Well you have two kinds of release that can be done:
And the next one, when you want to remove the scrollView from the main view:
由于
addSubview:
会保留scrollViewright
,因此您可以在addSubview:
之后立即释放它,或者添加一条autorelease
消息。首先声明它:请注意,scrollViewright是viewDidLoad内部的局部变量,因此在该方法之外不可用。
Since
addSubview:
will retainscrollViewright
, you can release it right afteraddSubview:
or add anautorelease
message when you first declare it:Note that
scrollViewright
is a local variable insideviewDidLoad
so it is unavailable outside that method.