hello I want to have the push segue default animation while Presenting View Controller.
I have three controllers In my storyBoard. FirstController is attached to the navigationController. first controller and second is connected through segue as present Modally. I am launching the third controller from second controller like this
let takeProductPhotoController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("takeProductPhotoController") as! TakeProductPhotoController
let nav = UINavigationController(rootViewController: takeProductPhotoController )
self.presentViewController(nav, animated:true, completion:nil)
The problem is ThirdController is popping up like modally I mean from the bottom which I don't want. I want to have a animation like push segue
I think It will work If I do self.pushViewController but pushViewController is not in this self
You need to do:
self.navigationController?.pushViewController(nav, animated:true)
Related
I am working with UISplitViewController. I have UISplitViewController which contain UITabBarController. So I want to display tab bar in all the screen through out the application (Even in detail screen of UISplitViewController for iPhone). Please see the approach:
use segue to move from one controller to another controller or move via navigation so in the next controller your tabbar will be show
just like if u want to move from A to B Controller set stroyboard id ie "SecondVc"
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "SecondVc")
self.navigationController?.pushViewController(vc, animated: true)
or just make connection using storyboard
I am using navigationController?.popToRootViewController(animated: true) to dismiss my current view to the previous view. My view controller relationship looks like this.
VC1->VC2
VC1->VC3
VC3->VC2
Whenever the client is in VC2 I want to pop the navigation controller back to VC1. This works fine when the rootviewcontroller is set to VC1. However, when the client uses a segue from VC3 to enter VC2, the rootviewcontroller is set to VC3 and the navigation controller pops to VC3.
I tried to change the rootviewcontroller like this.
// set root view controller
let appdelegate = UIApplication.shared.delegate as! AppDelegate
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let VC1 = mainStoryboard.instantiateViewController(withIdentifier: "VC1") as! FirstViewController
appdelegate.window!.rootViewController = VC1
navigationController?.popToRootViewController(animated: true)
But this actually returns the viewcontroller to the root view controller (VC1) even before the line "navigationController?.popToRootViewController(animated: true)" is executed so there is no animation.
Is there any way to set the rootviewcontroller of a navigation controller without presenting the root view controller right away?
If you put appdelegate.window!.rootViewController = VC1, the stack of controllers has died, you only have in the stack an alone Controller, therefore you can't apply popToRootViewController.
If this is your required navigation, maybe, this post helps you:
I got the problem is I cannot make go back previous ViewController of different storyboard from NavigationController in TabViewController.
I've already tried with
_ = navigationController?.popViewController(animated: true)
unfortunately, it does not work. And I know that it can be going back with segue but it's not good practice. Please let me know how to do it. Thanks. Following is my hierarchy.
I had the same issue. In this case I am on a different Storyboard and want to return to the Main Storyboard and present the first view controller. Since this controller is embedded in a Navigation Controller that is embedded in a Tab Bar controller, you must instantiate the Tab Bar Controller. Be sure to set the indentifier on the Tab Bar Controller as "TabBarController"... or whatever you like.
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: "TabBarController") as! UITabBarController
self.present(controller, animated: true, completion: nil)
I have three view controllers:
messagesVC: doesn't have navigation controller a chatting room
viewControllerA: has navigation controller and directs to messagesVC
viewControllerB: has navigation controller and directs to messagesVC
All three view controllers have their own storyboard for organization purposes. Right now, I created a storyboard segue to move from vcA or vcB to messagesVC.
I want to be able to put messagesVC on either vcA or vcB each time it's shown so that push view controller animation would work instead of presenting messagesVC modally. How would I achieve this??
In situation when you have segue in storyboard, choose the type of it 'show'.
When your messageVC is in another storyboard, you should load it like this:
let storyboard = UIStoryboard(name: "VCAStoryboard", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("messageVC") as! MessageVC
Then push it like this:
nvaigationController!.pushViewController(vc, animated: true)
This will do the job.
My view hierarchy looks like image below:
My problem is I want to show VC1 when I click any button on VC3. Here is my code
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("registerNavigation")
self.presentViewController(vc, animated: false, completion: nil)
but I got this warning "Warning: attempt to present ViewController whose view is not in the window hierarchy" and nothing happen. Please tell me, what did I do wrong?
If you want to show VC1 from VC3 the you not need to present it again because it is already loaded in navigation stack. you just need to dismiss or pop VC3 and VC2 from navigation stack. If you have presented it then dismiss and if you have pushed it then popped it.
Your warning's meaning : you are trying to presenting which is in the view hierarchy of navigation controller 1 but not in the view hierarchy of navigation controller 2.!!
Hope this will help :)
You are presenting to navigationController so use code like below.
let VC1 = self.storyboard!.instantiateViewControllerWithIdentifier("registerNavigation") as! ViewController
let navController = UINavigationController(rootViewController: VC1)
self.presentViewController(navController, animated:true, completion: nil)