我在我的应用程序中使用了 3 个 UIViewController,现在我想知道当我从另一个应用程序切换到另一个 UIViewController 时释放它们是否是一个好主意。显然,这将是隐藏的,当它们不可见时我真的不需要它们...... 要切换 View ,我使用类似这样的东西(uiwindow):
//this is in the first UIViewController
[[[UIApplication sharedApplication] keyWindow] addSubview:secondController.view];
[self.view removeFromSuperview];
//here I release the view controller
[self release];
所以我的问题...这真的值得吗?可能存在哪些性能问题?
另外,我想问是否有人知道为什么这些行按这个顺序工作(见下文)。我尝试了相反的方法,但我遇到了停止工作的方向问题?有什么提示吗?
//working
[[[UIApplication sharedApplication] keyWindow] addSubview:secondController.view];
[self.view removeFromSuperview];
//not working
[self.view removeFromSuperview];
[[[UIApplication sharedApplication] keyWindow] addSubview:secondController.view];
谢谢
劳尔
最佳答案
... it's that really worth it? what could be the performance issues?
一旦将 View Controller 添加为另一个 View ( super View )的 subview ,您就可以很好地释放它,在这种情况下, super View 保留 subview 。 [[UIApplication sharedApplication] keyWindow]是secondController.view的superView,并且它保留了secondController.view。因此,这是正确的方法,不会导致任何性能问题。
关于iphone - 释放 UIViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6896064/