How to do a real transition with iOS instead of modal? - ios

From what I understand, modal is sort of like a pop up presentation of a view controller? So that means that the view controller that is calling presentViewController is still there?
What is the proper way of transitioning to another view controller without it just being a modal popup? (Meaning it is not a parent-child relationship between the two, I guess)

I think you want to use NavigationController to push other ViewController. Sorry if i have wrong answer
This is guide about NavigationController for you
http://www.raywenderlich.com/113388/storyboards-tutorial-in-ios-9-part-1

Related

Is it possible to segue from a modal view to a view that is not in the hierarchy on a Navigation Controller in swift?

On my main view in a NavigationController I have a button that brings up a new view modally to submit a post. I have a button to dismiss this view which brings the user back to the main view, however if the users proceeds to make a post, I want it to dismiss the view and proceed to a show the post in the Navigation controller.
The ideal effect would have the standard navigation controller's back button on the top that can bring the user back to the main view when they have finished looking at their post.
I have tried several different methods, but I tend to get an error stating "Warning: Attempt to present (The View I Want to Show) whose view is not in the window hierarchy!
Thanks for any info!
Yes, it's possible. This is the best way I've found to structure the app to allow this functionality.
RootViewController
UINavigationViewController
ContentViewController (your current "main" view controller)
You're basically going to create a new RootViewController that is going to contain your current UINavigationController as a child. I usually setup the window.rootViewController programmatically in the AppDelegate. I would also keep a global reference to it.
Have a look at Apple's documentation on this. Basically, the RootViewController code would look like this:
[self addChildViewController:navController];
navController.view.frame = self.view.bounds
[self.view addSubview:self.navController.view];
[navController didMoveToParentViewController:self];
Now, whenever you need to present a modal view controller, present it from the RootViewController, instead of the current/top view controller on the UINavigationBar. This allows you to manipulate the UINavigtaionController independently and you won't get the error you're seeing.
So present the modal view controller from the RootViewController, this covers the UINavigationController and its content (top view controller). Make any changes you need to the UINavigationController stack (push, pop, etc...) with no animation. When you're done dismiss the modal view controller (with animation) and it will show you're adjusted UINavigationController.
Hopefully, this all makes sense. It's kind of complex and hard to explain in text. :p
If you don't want to setup a RootViewController, you might want to try presenting the modal view controller from the UINavigationController, as that might have the same effect. From the view controller just do self.parentViewController.present.
The main thing you're trying to avoid is presenting a modal from a view controller and then removing that view controller (pop) before the modal is dismissed. The view controller that presents the view controller is responsible for dismissing it.
I finally got it all working (I'm still new to Swift) and the two comments on the question were very helpful. The most helpful of all was the top answer here's example on github.
Similar question

UINavigationController vs viewController embed in NavigationController

I was trying my hands on iOS and while building apps, one question get into mind that what is the difference between UINavigationController vs viewController embed in NavigationController.
While using UINavigationController we push and pop views.
while using viewController we present and dismiss.
SO what are the applications where one is more superior to use than the other.
UINavigationController is used where you want you move back and forth in your application. Generally Navigation controller is used when you are navigating in more detailed information in each level of depth you are in your application.
UIViewController is generally preferred when you display polished information. in UINavigationController generally it is the one of the last controller you push in your controller
I think you are really describing two sides to the same coin. There is only one way to use a UINavigationViewContorller. It is a known as a container view controller and its job is to push and pop other UIViewControllers. A UINavigationViewController works with viewControllers, not views.
UINavigationController:
If you have hierarchy of view controller then that is you have stack of view then you need to use navigation controller. You can perfrom push and pop operations on the view controller and Navigation Controller is the rootViewController of all ViewController.so to go back to the previous one, in a ordered way. Imagine that controllers in a navigation controller will just build a sequence from left to right.
UIViewController: if you are using view controller it act as presentViewController. The presentViewController offers a mechanism to display a so-called modal view controller; i.e., a view controller that will take full control of your UI by being superimposed on top of a presenting controller. I think that presentViewController is most suitable for use with just one view controller being presented at a time. So you simply will not be able to implement a "go back"/navigation like functionality.
UINavigationController inherits from UIViewController. The strange thing about this object model is the UIViewController has a property called NavigationController. So for OO purists this is a bit baffling that a parent class knows about its children. But moaning aside this is how it’s been done in UIKit. As you’ll find with a runtime error, you can’t place a UINavigationController inside a UINavigationController
Whenever you push a controller, it can access the parent UINavigationController it may or may not belong to via the NavigationController property. The property is null if the controller is not inside a UINavigationController.

Get a reference to the currently visible view controller

I have a UIAlertView. When the user taps a button in the alert view I want to show a new UIViewController.
In order to achieve this I need to know which view controller is currently visible on screen because that particular view controller is the right one to present the new view controller.
The problem is that I have a complex hierarchy of view controllers in my app including a UINavigationController and a UITabBarController (among others). So I cannot simply use self.visibleViewController to get the currently visible view controller.
I have found a possible solution on Stackoverflow but I would like to find a neater solution without having to dig through the whole view controller stack.
UINavigationController has a property called topViewController.
Maybe it helps you.

difference between presentViewController and UINavigationController?

Please tell the difference between presentViewController and UiNavigationController? Could I use presentViewController instead of UINavigationController to navigate different views in the app?
Whats the scenario to use either?
presentViewController offers a mechanism to display a so-called modal view controller; i.e., a view controller that will take full control of your UI by being superimposed on top of a presenting controller.
UINavigationController offers a much more flexible mechanism where you can push a new controller, and later pop it, so to go back to the previous one, in a ordered way. Imagine that controllers in a navigation controller will just build a sequence from left to right.
I think that presentViewController is most suitable for use with just one view controller being presented at a time. You can surely use it to stack more view controllers one on top of the other (and thus sort of "mimic" a poor-man's navigation controller), but my bet is you will quickly find something not working as you expected.
Specifically, an example of such limitation is the following: when you dismiss a modal view controller (in order to "close" it), all of your modally presented view controllers (from the same presenting controller) will also be dismissed at once. So you simply will not be able to implement a "go back"/navigation like functionality.
So, it depends on what you are trying to do.
A UINavigationController is a subclass of UIViewController that manages a stack of view controllers and adds a back button etc.
presentViewController is a method of the UIViewController class you use to present a modal view controller.
The UINavigationController maintains a navigation stack for you. You are then able to navigate through hierarchical content.
http://developer.apple.com/library/ios/#documentation/uikit/reference/UINavigationController_Class/Reference/Reference.html
If you use UIViewControllers presentViewController method you are basically just replacing the view controller. no navigation stack is maintained for you.
UINavigationController is a class, presentViewController is an instance method of UIViewController (iOS 5 + ), of which UINavigationController is a subclass.
pushViewController is a comparable method to presentViewController. It is an instance method of UINavigationController, for iOS 2 +

Presenting full screen modal views from a UISplitView?

Just looking for some advice. What is the best way to present a full screen modal view controller from a UISplitViewController (set as the root) ?
There's no difference presenting a modal view controller from a UISplitViewController that from any other UIViewController.
You simply call - (void)presentModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated.
Do you know how to make a full screen controller?
Do you know how to present a modal view controller?
Are you having any problem combining the two?
Try it and if you have a specific problem ask about that.

Resources