关闭 UIViewController 视图并释放内存
所以我有一个 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
UIView
的任何子类始终保留其子视图。因此,在将UIView
作为subview
添加到另一个UIView
后,对其调用release
是安全的。但是,当发送dealloc
时,父级将在子级上调用release
,因此这假设您只想让子级在父级的生命周期内持续存在。Any subclass of
UIView
always retains its subviews. Therefore it is safe to callrelease
on aUIView
after adding it as asubview
to anotherUIView
. However, the parent will callrelease
on the child when it is sentdealloc
, so this assumes you only want to child to persist for the life of the parent.当您将视图插入视图层次结构时,
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.