关闭 UIViewController 视图并释放内存

发布于 2024-12-28 11:46:15 字数 341 浏览 2 评论 0原文

所以我有一个 UIViewController,我通过委托呈现它的视图,代码是:

[self.delegate fullStrViewController: self addFullScreenSubview:fullSize];

其中 fullSize 这里是我呈现的 UIViewController。在 fullSize 内部,我有一个 dimiss 方法,该方法基本上从超级视图中删除视图。问题是我实际上在哪里调用 fullSize 的释放?如果我在调用上面的委托之后执行此操作,那么当我调用 Dismiss 时,它将导致错误,因为 UIViewController 已被释放。有什么想法吗?

So I have a UIViewController that I am presenting it's view through a delegate, the code is:

[self.delegate fullStrViewController: self addFullScreenSubview:fullSize];

where fullSize here is the UIViewController I am presenting. Inside fullSize I have a dimiss method which basically remove's the view from the superview. The question is where do I actually call release on fullSize? If I did it after the call to the delegate above, when I call dismiss it will cause an error because the UIViewController has been released. Any thoughts?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

2025-01-04 11:46:15

UIView 的任何子类始终保留其子视图。因此,在将 UIView 作为 subview 添加到另一个 UIView 后,对其调用 release 是安全的。但是,当发送 dealloc 时,父级将在子级上调用 release,因此这假设您只想让子级在父级的生命周期内持续存在。

Any subclass of UIView always retains its subviews. Therefore it is safe to call release on a UIView after adding it as a subview to another UIView. However, the parent will call release on the child when it is sent dealloc, so this assumes you only want to child to persist for the life of the parent.

九厘米的零° 2025-01-04 11:46:15

当您将视图插入视图层次结构时,UIView 子类会保留视图。
当您的视图从层次结构中删除自身时,它将通过释放它来平衡保留。

如果此时您的对象没有其他引用,它将被释放。

开始使用 ARC,您就不必担心这些事情了。

a UIView subclass retains a view when you insert it into the view hierarchy.
It will balance that retain by releasing it when your view removes itself from the hierarchy.

If you have no other references to your object at that point it will be dealloced.

Start using ARC and you don't really have to worry about these things.

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