Is it possible to somehow call pushViewController after presentViewController was called in Swift?
Or at least I need to implement the same behaviour when new UIViewController appears from the left side. The only option that I got to develop was to fake pushViewController with CATransition() but in this case the mechanism of new UIViewController appearance is different from the native.
When you use native pushViewController new UIViewController appears over old one with fade.
When you use faked presentViewController while new UIViewController appears previous just moves out of the screen.
I also tried to use segue but in this case new UIViewController appears from bottom.
So I prefer just to call pushViewController after presentViewController if it is possible.
Thanks.
You need use a UINavigationController and set it's rootViewController to the UIViewController you want to present (from the bottom - as a modal).
Call presentViewController on that UINavigationController.
Then you can call pushViewController to push UIViewControllers onto the navigation stack and it will slide in from the side instead of the bottom.
Related
What is the advantage of using UINavigationController between a segue from one ViewController to ViewController ?
One could do it without a UINavigationController as well. And add a navigation bar and back buttons separately
The advantage of using UINavigationController between a segue from one ViewController to ViewController is that you can return previous ViewController by using UINavigationItem.
Like this,
This is why you don't need to implement transition. But this is one of the reasons.
If you want to know more details about UINavigationController, you can see that.
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UINavigationController_Class/
There are many useful methods in UINavigationController.
As a result, which is better to use UINavigationController's segue or just segue depends on your situation. If you don't know which is better, ask a question in stackoverflow again.
UINavigationController provides a Navigation Stack. You just push UIViewControllers but without extra afford you won't get an navigation which UINavigationController provides (back button and other stuff) and what most users expects when using an app
iam trying to make a UITbarbarController inside UISplitViewController
when making this segue modal it hides the MasterViewController ,when making it push Segue after reading apple Document we can't put UITabbarController inside UINavigationController,when i make the segue replace it doesn't animate and i cant dismiss the viewController anymore....
what is the best way to achieve this ?
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 +
I have one problem for which im not sure how to solve. Currently i have main UIViewController with some buttons. This is the initial view that is created with app. On it, one button calls storyboards segue with style Modal on ViewController which is part of UINavigationController. After that few other viewcontrollers are handled within the UINavigationController via segues and getting back via navigationController:popViewControllerAnimated. What i dont know is how to get back from UINavigationController to first UIViewController. I tried, when I'm on first one on navigationctrl,
[self removeFromParentViewController];
yet that only removes the view but it seems that UINavigationController somehow stays alive as result is black screen. Creating unconnected segue and call it from code would be possibility, but im not sure if that is the proper way. Would that leave navigation controller alive ?
Is there any reason you are using a UIViewController first and THEN a UINavigationController?
Why not change this so that the UINavigationController is the initial view controller and then drive everything from there.
If you want the first view to not have a nav bar then you can hide it easily.
That way you can move around through all views by popping and pushing through the UINavigationController.
I'm using a SplitViewController which can't be part of a navigation controller. I'm using SetRootViewController on an IBAction, which is fine, but it's not animated. Ideally I'd like to use the same animation as the Navigation Controller does (slide in from the left/right) but if that's not possible I'd like to use a consistent animation when ever I need to do this.
I'm not sure about this, but I would suggest the following.
Set the UISplitViewController as your UIWindow's rootViewController. In the viewDidLoad, you make a presentModalViewController:animated: call with the button's UIViewController as modal. Make sure you don't animate it. This gives you the illusion that the modal view is the first you see when the app launches.
When you push the button, you animate the button's UIViewController out with dismissModalViewControllerAnimated:. Now you can choose how to animate. One of your choices is cross disolve.
Using iOS 5.0 you will be able to use presentViewController:animated:completion to present the SplitViewController from your initial rootViewController.
Prior iOS 5.0 your only chance is using the transitionFromView:toView:duration:options:completion method on the rootViewController's view, which means you will have some effort with passing several messages to your SplitViewController manually. iOS prior 5.0 does not support container ViewControllers.
But probably you want to rethink your design.
You should set the SplitViewController as rootViewController initally. On App startup (or whenever you need to) you should present your LoginViewController modally.
When the user logs in successfully, you hide your modal view with whatever animation you want to choose.
Since the SplitViewController is your main ViewController it should be the rootViewController of your application.