iphone - 释放 UIViewController

标签 iphone cocoa-touch uiviewcontroller uikit uiwindow

我在我的应用程序中使用了 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/

相关文章:

iphone - UIViewController loadView 方法

iphone - COCOS2D中的ccc4颜色列表

javascript - PhoneGap : different behavior Simulator vs. 设备

iphone - 将 CGPoint 从 UIView 坐标系转换为 CALayer 坐标系

ios - 处理数据和 UITableViewCell 的更好方法是什么?

iphone - didReceiveMemoryWarning 和 viewDidUnload

iphone - cocos2d中boundingBox的起源是什么

iphone - XCode 中 AddNewfile 下没有 "UITableViewCell Subclass"选项?

ios - 在 Playground 的 UIViewController 上自动调整 UILabel 和 UIView 的大小

objective-c - 如何检测捏合手势与捏合手势?