如何释放Views?

发布于 2024-11-13 22:44:59 字数 385 浏览 1 评论 0原文

我在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

强辩 2024-11-20 22:44:59

好吧,您可以执行两种释放:

UIScrollView* scrollViewright = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0,400,768)];
[scrollViewright setContentSize:CGSizeMake(400,1000)];
[self.view addSubview:scrollViewright];
[scrollViewright release];

下一种是当您想从主视图中删除scrollView时:

[scrollViewright removeFromSuperview];

Well you have two kinds of release that can be done:

UIScrollView* scrollViewright = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0,400,768)];
[scrollViewright setContentSize:CGSizeMake(400,1000)];
[self.view addSubview:scrollViewright];
[scrollViewright release];

And the next one, when you want to remove the scrollView from the main view:

[scrollViewright removeFromSuperview];
滥情空心 2024-11-20 22:44:59

由于 addSubview: 会保留 scrollViewright,因此您可以在 addSubview: 之后立即释放它,或者添加一条 autorelease 消息。首先声明它:

UIScrollView* scrollViewright = [[[UIScrollView alloc] initWithFrame:CGRectMake(0,0,400,768)] autorelease];

请注意,scrollViewright是viewDidLoad内部的局部变量,因此在该方法之外不可用。

Since addSubview: will retain scrollViewright, you can release it right after addSubview: or add an autorelease message when you first declare it:

UIScrollView* scrollViewright = [[[UIScrollView alloc] initWithFrame:CGRectMake(0,0,400,768)] autorelease];

Note that scrollViewright is a local variable inside viewDidLoadso it is unavailable outside that method.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文