Calling popToRootViewControllerAnimated from a modal - iphone

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.

Related

Meaning of Modal Presentation/Stacking ViewControllers

I'm working on a project which has multiple view controllers stacked in a navigation controller, similar to this:
https://youtu.be/yl2m4fDOLQo
I fear that I may end up stacking too many view controllers in one navigation controller. I understand that once there are more than 3 view controllers stacked in a navigation controller, the views are presented "modally"
First of all, what is a "modal" presentation? I looked it up in Swift documentation but I'm having some trouble understanding how it differs from the navigation stack. Second, if there is a problem, is there any way around it?
I'm new to this so help is much appreciated,
Nick
I understand that once there are more than 3 view controllers stacked in a navigation controller, the views are presented "modally"
This is false. You can have as many view controllers in a navigation stack as your app needs, as long as the device has enough memory. View controllers in a navigation stack have a navigation bar (technically, this is part of the navigation controller), a back button and (hopefully) a swipe-right gesture that allow the user to go back "up" the stack. You add a view controller to the stack by calling pushViewController(animated:) and remove it by calling popViewController(animated:) on the navigation controller.
A modal view controller exists outside of the navigation stack. It does not have a navigation bar because it's not in a navigation controller. You are responsible for adding some way to dismiss the modal, such as tapping a close button placed manually in the view controller's view somewhere. You can even add a navigation bar instance manually and put a close button in it. You show a modal by calling present(_:animated:completion:) on the currently-displayed view controller and dismiss it by calling dismiss(_:animated:completion:).

How to make a login page view xcode navigation and tabbar controller push pop views

I've tried many different ways but can't get it to work. How can I make a simple login/logout view/app? I need the initial page to be a regular UITableView, once login button is pressed it should (push/addsubview ?) to a new UITabBarView (with 2 UITableViews in that), on the second tab exists a logout button, which should send you back to initial login page, also on the login page the nav controller and tabbar should never show up, (but I think I can figure that out). I tried pushing and popping viewcontrollers put that's getting messy. Xcode 4.1
Examples or help will keep me from pulling the little hair I have left out!
Thank You!
I 've wrote some thing, may be it took complex to understand by you but i've tried to explain, main theme is that to make a navigation controller and set it to app delegate window's root view controller then push login view controller to it, and then pushing tabbar controller, read below some explanation.
this is mostly done by making a navigation controller and setting it the app delegate window's root view controller, then make a view controller that is your login view and setting it the root view controller to app delegate's navigation controller, then make a tabbar controller (a view controller) which contains tabbar and navigation controllers on each tabbaritem, and furhter each navigation controller has a reference to tabbar controller(the view controller pushed at login time). So, whenever logins is pressed, it pushes the tabbarcontroller and performs tasks. and when you want to logout, just pop to root view controller of the referenc's navigation controller which in fact is the login view controller.
You can hide tabbar, then show it after login success.
https://github.com/idevsoftware/Cocoa-Touch-Additions/tree/master/UITabBarController_setHidden

PresentModalViewController, PushViewController, then DismissViewController with a new view shown?

I have a UINavigation controller setup. I was hoping to do this:
From one of the views, I presentModelViewController:animated:, the user selects one of three options, after selecting I want the UINavigationController behind the modal view to change (the user will not see this), then I want to dismissModalViewControllerAnimated to reveal the new view.
Is this possible using the built-in modal view? Or will I need to create a view, add/animate it to the rootViewController so its not in the same stack as the UINavigationController?
Thanks!
A modal view is a view you show modally on top of another view to interrupt the user from the current task. If I understand you correctly, you need two modal views and the selection user make on first modal view will decide what will show as the second modal view. Is that right?
If that's the case, you can make your main view to be the delegate of your first modal view, and send data back to the main view when the user makes a selection, and then main view dismiss the modal view (it's the main view's responsibility to dismiss it). And then based on user's input, you create another view and pop it modally. To make it animate correctly, you need to set the animation of the dismissing of the first modal view to be NO, and then make the animation of populating second modal view to be YES.
Hope this helps.

Understanding View Controllers

I have an TabBar application with 4 tabs. All four tabs have navigation controllers. In the settings tab i have a table with a cell for "Feedback". When the cell is clicked a FeedBackView controller is pushed which contains a feedback form with a few fields. This has a textfield for Category. When the textfield is touched, a modal view controller (FeedBackModalView) is presented with a picker. In the viewDidLoad method of the FeedBackModalView controller I typed NSLog(#"%#", self.parentViewController). In the console it shows the parentViewController as TabBar controller. Why is that? Shouldn't it be showing the FeedBackView controller as the parentView since I'm presenting the modal view in that controller?
I hope i was clear.
Using presentModalViewController with UITabBarController has some issues, and I believe the internal behavior of the method has kept changing in recent SDK versions. The bottom line is, you are supposed to use the root view controller to modally present a view controller. In case you are using tab bar interface, that becomes the UITabBarController object.
In an old version of SDK, when I presented a modal view in a view controller inside a tab bar controller the modal view did not appear in full screen, which wasn't an expected or a documented behavior. Now a modal view seems to appear in full screen anywhere, and I wouldn't be surprised if [self presentModalViewController:animated:] method internally checks self and if it has non-nil parentViewController property, send the message to the parent view controller (which will explain your observation).
My memory is vague and perhaps somebody has to correct me. However, I still believe it's the straightforward thing to understand (and also maybe practice) presentModal... only works with the root view controller.

modalViewController still set after dismissModalViewController

I have a main screen that presents a modal view controller.
When the modal controller is done it calls a method on the parent to dismiss the modal and then display a different modal view.
The problem is that after dismissing the modal view controller (the view does correctly disappear) the subsequent presentModelViewController doesn't do anything.
If I look at the modalViewController property on the root controller I can see that after doing the dismiss it is still set to the old modal controller. As noted above the view is no longer visible and also if I profile the application there are no instances of that view in memory.
Any ideas?
The problem was that the modal controllers viewDidDisappear had not been called before I was adding a new modal controller.
Once I ensured that I only tried to add a new modal after the original modal viewDidDisappear had been called it worked ok.