gpt4 book ai didi

iphone - 释放 UIViewController

转载 作者:行者123 更新时间:2023-12-03 21:18:53 28 4
gpt4 key购买 nike

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

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com