简体   繁体   中英

How does a modal view controller work with the stack?

Im new to iPhone programming. And, im trying to make a game with like 200 levels. I want to use modal segueing because i dont want the naviagational bar at the top, and also i want the cross dissolve animation. Say I have vc one. And then I have vc 2

ok, so vc 1 segues modally to vc 2

and then i have a button on vc 2 to segue back to vc 1

so, does the program know to pop vc 2 off the stack? or did i just create a memory leak so that now vc1, vc2, and vc1 are on the stack instead of just vc1.

and then still also if i had vc1 to vc2, and vc2 to vc3, and in vc3 i have a button that goes back to vc 1, will the program pop both vc 2 and vc 3 off the stack? or will 4 be on the stack? And anyways, since with a modal segue theres no real back button (like in a navigational push segue theres always a back button on the navigational bar), does modal segueing even have a stack?

I mean, or is it independent? Like, say vc segues to vc2, and vc2 to vc3. Now, is vc 2, and 1 even on the stack? or is it just vc3?

sorry, im just a little confuzzled about all this, and im not sure how to make my game. Because if i have 100 view controllers with different levels, then surely in order to have modal segueing I would need to code some popping off vcs off the stack each time i segue right, so that i dont end up with 100s of controllers on the stack? And i dont even know how to tell my program how to pop off view controllers.

So a modal segue is mainly for presenting content that interrupts the usual flow of the application. It isnt really a good fit for presenting several view controllers sequentially because, as you say, if you have a segue that goes back to the first view controller it doesn't pop anything off the stack.

You want to look for one of the Apple provided View Controller containers to see which one would best fit going through a sequential list of view controllers.

The page view controller is useful because it only keeps one or two view controllers loaded at a time and as of iOS 5 you can set the transitionStyle property to 'UIPageViewControllerTransitionStyleScroll' to scroll left and right (or up and down) between view controllers.

If you dont like the view controllers apple provides for this then look at the documentation for UIViewController about how to write your own custom container view controller. This way you can define your own stack, pop the stack as needed and have a dissolve transition.

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html%23//apple_ref/doc/uid/TP40006926-CH3-SW81

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