简体   繁体   中英

ViewController viewDidLoad after presentModalView called?

I have a viewController called "FirstViewController". In an IBAction i call another ViewController called "thePageFlipViewController" and push it in sight via

[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:

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

And here is my problem:

-viewDidLoad in FirstViewController get's sometimes called after dismissing thePageFlipController . I don't understand why, because firstViewController should live in background. Is it dependent how long the modal view is displayed? is it possible that ARC does release something?

My problem is, that i initialise a lot of objects in viewDidLoad and the app crashes if viewDidLoad gets called again. I define some Routes for RESTKit there and RestKit complains that the routes are already set up and crash the app.

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. 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: .

See the Memory Management section of the UIViewController class reference.

Also this answer has a good explanation already.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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