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
Related
My Storyboard is setup as:
UIViewCont
/
NavigationController -> UIViewContr -> UIViewContr ----- UIView Contr
\
NavCont
\
TableViewController
The last three controllers (2 x UIView and 1 x TableView) use "show" segues from three different buttons. And the TableView controller is embedded in the NavCont.
Because the first controller is a NavController every UIViewController has a back button except the TableViewController.
I've been reading up about it but can't figure out why. Other than each Navigation controller is it's own stack and kind of starts again so you can't just navigate back from a 2nd or 3rd navigation controller. But not sure.
Thanks.
Using a navigation controller resets the navigation stack tracking, so your table view does not have a back button because it is effectively a new root. If you create a view controller that the table view segues to, it will have a back button because it is part of the (inner) navigation chain and not the root.
It is not apparent from your example what you are trying to do or why you have the inner navigation controller instead of just relying on the original navigation stack. There is one option you can try. The root view of a navigation stack should have the navigation bar, and you can drag bar button items onto it, allowing you to unwind back to the previous state.
I'm trying to create an app using storyboard which has 4 scenes:
ChooseLoginMethod
EnterLoginData
SuccessfulLogin
MainScene.
What I'm doing right now is the following: I have an UINavigationController which has ChooseLoginMethod as its root view. ChooseLoginMethod has several buttons (for different login methods) which are push segues to EnterLoginData. EnterLoginData has a push segue to SuccesfullLogin and SucessfullLogin has a push segue to MainScene.
The problem is that SuccessfulLogin and MainScene display the back button on the top bar, which makes no sense for the application.
I've tried:
Hidding the top bar on these two Views. Not successful.
Changing the segue to modal. Seems to work, but doesn't feel like the right thing to do.
So what I would like to do is create a segue which breaks the chain of Views which are on the UINavigationController's stack. Is there a proper way to do this in storyboard?
-- edit --
Maybe what I should do is replace the root view ( Set root view for UINavigationController ). This may work, but seems like a programming work-around for something that should be possible to be done in storyboard. Or maybe it is just me not getting the "iOS way of doing stuff".
You had to use setNavigationBarHidden before the viewcontroller appears on the screen, like in viewWillAppear.
But then you can't go back from "MainScene" to the "RootController". So you should do something like popToRootViewController after "SuccessfulLogin" and then pop "MainScene".
I think it's usually best to have your main scene be the root view controller. From its viewDidAppear method, you can present your ChooseLoginMethod controller modally, and from there do modal transitions to your other login controllers. When you get to the end, and you want to go back to the main scene just dismiss the modals from the root view controller -- this will dismiss the first one, and any that were presented from it:
[self.view.window.rootViewController dismissViewControllerAnimated:YES completion:nil];
I have two UIViewControllers, vc1 and vc2.
I want to switch between them. But before loading the view of the new view controller, I want to destroy/release/remove (I'm not sure abt the correct word to use here) the previous viewcontroller.
For example, when I am switching to vc2 from vc1 ,I want to destroy vc1 completely, so that when I return to vc1 from vc2, vc1 will be loaded from scratch (i.e. viewDidLoad will be executed).
Which type of view switching should I opt for?
presentModal...
addSubview.
I am not using a navigation controller.
Currently I am using the presentModal... method, but when I use dismissModalViewcontroller on the newly presented view controller, it doesn't show up a new instance of the previous view controller. Instead, it shows the already running instance of it.
I want the viewDidLoad method of the previous view controller to run when I dismiss the newly presented view controller.
What exactly needs to happen in viewDidLoad?
You also have viewWillAppear available to you, so it could be that you could move the required functionality there and still use the modal presentation.
See this answer. You can do this with or without animation.
Animate change of view controllers without using navigation controller stack, subviews or modal controllers?
I have a navigationController, I push a new viewController onto it's stack, I have been trying to figure out a way to switch this ViewController with another viewController from within the first ViewController.
I have 3 almost identical views, depending on the user interaction I would like to be able to switch between these views within the same stack index i.e. without pushing or popping views on the navigationController.
So if view C has index 3 on the navigationController stack and the user taps a certain button in view C the C1 view replaces C on the stack and gets index 3.
I have been through the UINavigation Class and can't find a way around this.
If I popViewController from within the current viewController and the tries to pushViewController… well that can't be done as the viewController gets released when popping it. If I instead try to do pushViewController, well then I gets added on top of my current viewController.
I hope it makes sense and that someone can help me out:)
Thanks
You can assign an NSArray of controllers to the viewControllers property to alter the entire stack instantaneously.
Is my assumption that every controller which is presented with presentModalViewController:animated: need their own UINavigationController stack for their own hierarchy of drill down controllers? Meaning, say I have a top level controller It has its own navigation stack, and an action button which presents another controller via a modal. That modal has its own navigation stack. Is it best to split each modalView with its own Navigation stack?
If you want a modal view to have the forward-and-back behavior provided by a navigation controller, you need to provide a separate navigation controller for it. (If you don't need to push and pop view controllers inside that modal view, then you don't need one, of course.) This can be a bit of a pain, but them's the breaks.