简体   繁体   English

在presentModalView之后调用ViewController viewDidLoad吗?

[英]ViewController viewDidLoad after presentModalView called?

I have a viewController called "FirstViewController". 我有一个名为“ FirstViewController”的viewController。 In an IBAction i call another ViewController called "thePageFlipViewController" and push it in sight via 在IBAction中,我调用了另一个名为“ thePageFlipViewController”的ViewController,并将其通过

[self presentModalViewController:thePageFlipViewController animated:YES];

after some time the user closes thePageFlipViewController with a button where the following code is executed via a delegate in FirstViewController: 一段时间后,用户使用按钮关闭PageFlipViewController,在其中通过FirstViewController中的委托执行以下代码:

[self dismissModalViewControllerAnimated:YES]; [thePageFlipViewController release];

And here is my problem: 这是我的问题:

-viewDidLoad in FirstViewController get's sometimes called after dismissing thePageFlipController . -viewDidLoad在FirstViewController得到的有时驳回后调用thePageFlipController I don't understand why, because firstViewController should live in background. 我不明白为什么,因为firstViewController应该住在后台。 Is it dependent how long the modal view is displayed? 它取决于模态视图显示多长时间? is it possible that ARC does release something? ARC是否有可能发布某些内容?

My problem is, that i initialise a lot of objects in viewDidLoad and the app crashes if viewDidLoad gets called again. 我的问题是,我初始化了很多viewDidLoad中的对象和应用程序崩溃,如果viewDidLoad被再次调用。 I define some Routes for RESTKit there and RestKit complains that the routes are already set up and crash the app. 我在那里为RESTKit定义了一些路由,而RestKit抱怨这些路由已经设置并导致应用崩溃。

Any Help is appreciated. 任何帮助表示赞赏。

When a view is not actually displayed it can be unloaded to free up memory. 当视图未真正显示时,可以将其卸载以释放内存。 You would get a call to viewDidUnload: when that happens so you can release any objects you are holding strong references to. 您将获得一个对viewDidUnload:的调用viewDidUnload:发生这种情况时,您可以释放所有拥有强大引用的对象。 Then next time the view is needed, viewDidLoad: will get called again when the view is reloaded, there you have to recreate the objects you released in viewDidUnload: . 然后,下次需要该视图时,将在重新加载视图时再次调用viewDidLoad:在那里您必须重新创建在viewDidUnload:释放的viewDidUnload:

See the Memory Management section of the UIViewController class reference. 请参阅UIViewController类参考的“ 内存管理”部分

Also this answer has a good explanation already. 而且这个答案已经有了很好的解释。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM