故事板控制器不能解除分配 [英] Storyboard Controllers not Deallocating

查看:112
本文介绍了故事板控制器不能解除分配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

故事板的我的初始视图控制器使用 performSegue:withIdentifier 方法加载另一个视图控制器,该方法又使用相同的 performSegue:withIdentifier加载其他控制器方法。

My Initial View Controller of the storyboard load another view controller using performSegue:withIdentifier method which in turn loads some other controller using same performSegue:withIdentifier method.

但是,初始视图控制器和第二个视图控制器都没有解除分配。通过仪器可以看到它们的参考数都是1。

However, neither the initial view controller nor the second view controller are deallocating. They both tend to have a reference count of 1 as seen via instruments.

我需要在用户退出应用程序时将用户送回第一个控制器。我到目前为止唯一的方法是使用 performSegue:withIdentifier 方法并将用户发送回初始控制器。

I need to send user back to first controller when he logs out of application. The only way I have figured so far is to use performSegue:withIdentifier method and send the user back to initial controller.

然而,我担心以前的控制器不会被解除分配,导致重新创建相同的视图控制器。

However, it concerns me that previous controllers will not have been deallocated thus, resulting in re-creation same view controllers.

因为我需要将用户注销回第一个屏幕,我想确保所有以前的视图控制器都已被释放。

Since I need to logout a user back to first screen, I want to make sure that all previous view controllers have been deallocated.

推荐答案

当你执行推送或模态segue时,它不会(也不应该)释放你正在查看的视图控制器。它需要保持它,以便当您弹出/关闭它时,它仍然会存在。此规则的例外是使用拆分视图控制器并使用替换segue时。但这是一个特例。

When you perform a push or modal segue, it will not (and should not) release the view controller from which you're seguing. It needs to keep it so that when you pop/dismiss back to it, it will still be there. The exception to this rule is when using a split view controller and you use a replace segue. But that's a special case.

如果你想回到第一个场景,如果你使用导航控制器并且只使用push segues,你可以使用 popToRootViewControllerAnimated 。 (对于iOS 5目标,我将始终使用导航控制器,并且如果我不希望它可见则隐藏导航栏。因此。能够弹回多个级别很方便。实现相同效果很麻烦使用模态segues。)在iOS 6中,您可以使用展开segue ,您可以在其中弹出/取消任意例如,场景的数字级别,以返回到您的初始场景。

If you want to go back to the first scene, if you're using a navigation controller and using only push segues, you can use popToRootViewControllerAnimated. (For iOS 5 targets, I'll always use navigation controller, and hide the navigation bar if I don't want it visible, for that reason. It's convenient to be able to pop back multiple levels. It's cumbersome to achieve the same effect with modal segues.) In iOS 6, you can use an unwind segue, in which you can pop/dismiss back an arbitrary number level of scenes, for example, to return to your initial scene.

这篇关于故事板控制器不能解除分配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆