调用presentModalViewController后卸载View?
我有一些视图控制器,我使用以下方法调用它:
myViewController *myView = [[myViewController alloc] initWithNibName:nil bundle:nil];
myView.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:myView animated:YES];
[myView release];
如果我使用该应用程序几次,我会收到内存警告,并且应用程序会冻结几秒钟!我认为原因是我切换了视图但没有释放旧的视图!!?!!!?!! (我将插座设置为零并释放它们)
切换到新视图后如何卸载旧视图?
提前致谢
I have some view controller which I call with the following method:
myViewController *myView = [[myViewController alloc] initWithNibName:nil bundle:nil];
myView.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:myView animated:YES];
[myView release];
if I use the app a few times I get a memory warning and the app freezes for a few seconds! I think the reason is that i switch the view but not discharged the old one !!?!!?!!
(i set my outlets to nil and release them)
how can I unload the old view after switching to the new one?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
切换视图时,请务必在 myViewController 上调用dismissModalViewController:(BOOL)animated。
When switching the view be sure to call dismissModalViewController:(BOOL)animated on myViewController.
在启动 modalViewController 的类中,您可以为保留的模态视图控制器创建一个属性。然后你可以写这样的东西。
然后而不是设置
将该代码移至 modalViewController 并写入 self.modalTransitionStyle = UIModalTransitionStyleCoverVertical; 我认为这看起来更干净,保持每个视图控制器的配置分开,不要混淆。
正如maclema所说,调用dissmissModalViewController,但你可能正在这样做......
In the class that launch the modalViewController you could make a property for the modal viewcontroller which you retain. Then you could write something like this.
Then instead of setting the
Move that code to the modalViewController and write
self.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
I think that looks cleaner, keep the configuration of each viewcontroller separted don't mix it up.And as the maclema said, call
dissmissModalViewController
, but you probably are doing that...可能会出现很多问题,但您不需要(也不能)卸载旧视图。确保在所有视图控制器的 viewDidUnload 中释放对象并将出口设置为 nil。当发生内存警告时,
viewDidUnload
将被调用,因此如果您没有正确处理它,就会出现泄漏并可能崩溃。除此之外,很难知道您的应用程序还做了什么导致崩溃的事情。Could be any number of problems but you don't need to (and can't) unload the old view. Make sure you are releasing objects and setting outlets to nil in
viewDidUnload
of all of your view controllers.viewDidUnload
will be called when a memory warning occurs so if you don't handle it correctly you'll have leaks and can crash. Other than that, hard to know what else your app is doing that is contributing to the crash.