释放 UIView 后如何重新创建它?
在我的 MainWindow.xib 中,我有很多视图控制器。其中一些显示为模态视图,另一些则只是插入。我担心内存管理可能较差,因为我没有释放我创建的任何视图(dealloc 方法中除外)。但是,当我释放视图时,我的应用程序无法将其恢复。我的问题是,如何释放视图以释放内存,但在需要时恢复视图。
PS 我唯一拥有的 .xib 是 Mainwindow .xib。其他视图都是在界面构建器中作为视图控制器创建的。
In my MainWindow.xib I have many view controllers. Some of which are displayed as Modal views, and others are simply inserted. I am concerned with possible poor memory management because of the fact that I am not releasing any of the views that I create (except for in the dealloc method). However, when I do release a view my app can't bring it back up. My question is, how can I release a view to free up memory, but bring the view back when it is needed.
P.S. The only .xib I have is Mainwindow .xib. The other views were all created in interface builder as view controllers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以编程方式创建视图或使用更多 xib 文件。所以你可以在需要时分配 init 和释放。
Create your views programatic or use more xib files. So you can alloc init and release when you want.
我建议为每个视图控制器使用单独的 .xib,这样您就可以使用 initWithNibName:bundle 方法创建它们。
一般来说,如果您遇到这种性质的问题或疑虑,请阅读相关的编程指南文档——它们非常好,通常会向您展示正确的方法。
I would recommend using separate .xibs for each view controller, so you can create them using the
initWithNibName:bundle
method.In genearl, if you're having issues or concerns of this nature, read the relevant Programming Guide documentation -- they're very good and will show you The Right Way To Do it, generally.