I suspect many have had this case - you present modal view controller, which then present navigation view controller, that has many table view controllers pushing onto the stack. Basically, pushing and presenting controllers. When you get to last you have to dismiss them all, and return to root view controller
Do i have to call for every modal controller dismiss, and for every pushed controller pop, or is there a better way to do this?
I am using iOS5 storyboards if that is relevant somehow.
EDIT:
Thanks for answes but its little more complicated than that - basically i present modal view controller from root controller, than push couple of controllers, then present one more modal view. At that time I want to go to root controller. So just poping view controllers want do it, some of them have to be dissmised
You can return back to the root navigation controller by calling:
[self.navigationController popToRootViewControllerAnimated:YES];
And then release your modal view controller
Related
Lets say you present modal view controller (which is navigation controller) and push onto navigation stack 3-4 view controllers. Would dismissing modal view controller also pop these controllers from navigation stack, or will they continue to linger in memory?
I apple doc it states that when presenting multiple modal view controllers, if you dismiss the root one, all other will be dismissed, but animation of dismissal will happen only once. There is, however, no mention, what if you had pushed some controllers on modal view controller and then dismissed it.
When you dismiss the modal view controller, it will be deallocated from memory. So unless you keep a reference to it, everything will be removed, including its inner view controllers in the stack.
However, if you do keep a reference to it, it will stay alive when dismissed, therefore keeping its current state. Next time you present it, it will be just as you left it.
The navigation controller contains the view controllers that are pushed within it. So when the navigation controller is presented modally and then dismissed, it's (contained) view controller stack gets cleaned up, too.
I have a modal that I am calling presentModalViewController to display from a custom menubar. This menubar is overlaying a viewcontroller that is pushed from a tableView cell.
Now... that all being said, I need to find some way to jump the user back to the root of the tableView from the modal screen. Is this possible? I've been fighting with this for the past couple of hours with no results.
If you're starting from a tablview, drilling down to a detail view via a navigation controller, and then presenting a modal view controller on top of that detail view, you'd have two steps to get back to your list/tableview: First you'd dismiss your modal view controller, then you'd pop your detail view off your navigation stack.
That should put you back where you started (at the tablview), if I'm reading this correctly.
You could pass a reference to the navigation controller to the modal view, and then immediately after calling dismissModalViewControllerAnimated, you can use the reference to the navigationController to pop back to the root view controller.
I would like to place a UINavigation View within a Modal view but I am having loads of problems. I managed to get the modal view working, but when trying to put a UINavigationController in it it just comes up with a blank screen.
Does anybody know how to do that properly?
Create a UINavigationController, initialize it with your UIViewController at its root, and then present the navigation controller modally.
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.
I'm starting an app where I'd like to have multiple view controllers. Some of the views will be displayed inside of a navigation controller. I can create a navigation controller and then add another instantiated view controller to it. But what I'd like to do, is just instantiate a view controller that has its own view and is the root view controller of a navigation view controller. So when I instantiate the view controller, I'd like for it create a navigation controller and push "self" on to it. When I do it my simulator crashes and the details don't really give a reason. The console does not display anything. Any ideas. My reason for this is to separate out logic without have a view controller that simply creates a navigation controller and then pushes another view controller on it as the root view controller.
I'm not entirely sure if I understand your question correctly. Why would it be preferable if the view controller pushed itself to the navigation controller? I mean, you have to instantiate your view controller at some point in code (either app delegate or another view controller) anyway. Why can't you just create the navigation controller there, instantiate your VC and then push it onto the nav controller? As far as I can see, this doesn't involve creating any additional view controllers.
Anyway, having a view controller decide by itself where it is used (ie. pushed onto), is not best practice. This way you lose the flexibility of using it in other contexts. Always try to couple your components as loosely as possible.