I want to move to another view controller without using navigation controller, segue,storyboard and animation. Anyone can help me? - swift

I want to move to another view controller without using navigation controller, segue, storyboard and animation

You can use presentViewController like this
let controller = self.storyboard?.instantiateViewControllerWithIdentifier("YOUR_VIEWCONTROLLER_ID")
self.presentViewController(controller!, animated: false, completion: nil)

Related

swift - Dismiss presenting view controller without dismissing navigation controller?

I am trying to dismiss a modal and push a new view controller from the navigation controller, but the code bellow dismisses the navigation controller as well, so there is nothing to push to and the window collapses. This code is inside my routing class:
func navigateToVC() {
self.navigationController.presentingViewController.dismiss(animated: false, completion: nil)
self.navigationController.pushViewController(newVC, animated: false)
}
So is there a way to dismiss the presenting view controllers while keeping the navigation controller?
Use this to dismiss presented ViewController,
self.dismiss(animated: true)
Once you dismiss it , that's where you should push ViewController. You can't push after you dismiss your viewController because it's deallocated already.
I recommend creating a delegate and call it from your HomeViewController

Performing segue with UINavigationController (without IBAction)

It's easier to show you a drawing and then explain.
Dashboard Storyboard
I have 2 separate UIViewControllers (i've included just one in the drawing, the other is irrelevant) embedded in container view called ContainerViewController.
Post Storyboard
NewPostViewController shows a UIButton that presents TextPostViewController. As you can see, all of them are embedded in UINavigationControllers. Now, once the completion block of the new post is being called, I have to present the ContainerViewController and it needs to handle it's own logic. The problem is that it's embedded in UINavigationController and once I present it, the UITaBbar is hidden.
I tried to do this:
self.performSegue(withIdentifier: "TextPostToNavContainerVC", sender: nil)
The transition is successful but I'm losing the UITabBar, even though in the DashboardViewController and the ContainerViewController I called:
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
tabBarController?.tabBar.isHidden = false
}
What am I doing wrong or is there are better way to do that?
You should instantiate the tab bar controller. not the view controller.
Imagine you're putting a initial view controller ahead of your tab bar controller. Making your tab bar not being pushed
If I undestand it correctly.
You are doing this
Segue connect to a view controller
But you should actually do this Segue connected to a tab bar controller
You can try to add it as a child to control it's frame like this
let textPost = self.storyboard?.instantiateViewController(withIdentifier: "containerID") as! TextPostToNavContainerVC
textPost.view.frame = CGRect(x:20,y:0,width:self.view.frame.width,height:self.view.frame.height-50)
self.view.addSubview(nvc.view)
self.addChildViewController(textPost)
textPost.didMove(toParentViewController: self)

AVPlayerViewController not rotating

My custom AVPlayerViewController won't autorotate if the previous view controller has been instantiated. If I present the AVPlayerViewController, it rotates, and if I present the previous view controller, it rotates. Here's my code for instantiating a view controller :
let vc = self.storyboard!.instantiateViewController(withIdentifier: "MovieVC") as! MovieVC
vc.movie = self.movie
self.navigationController?.pushViewController(vc, animated: true)
In this situation I am creating a copy of the current view controller with different information. If there is no way to fix the autorotating error, is there a different way to present the same view controller?
The problem is that you are not presenting the view controller. You are pushing it. That means that the navigation controller itself is in charge of rotation, so you don't get any special autorotation for this view controller.
The only way to give this view controller its own power over autorotation is to present it:
self.present(vc, animated: true)

How to present a view controller inside a navigation controller SWIFT

I have VC1 which is a basic view controller, I then want to present VC2 which is inside a navigation controller. Whenever I present it, it doesn't display the navigation controller. I want this all done pragmatically. The code I have been using to present VC2 is:
func matchesPressed(sender: UIButton!) {
let matchesTVC: Matches = self.storyboard?.instantiateViewControllerWithIdentifier("Matches") as! Matches
self.presentViewController(matchesTVC, animated: true, completion: nil)
}
How do I present the navigation controller it is inside as well?
Is the navigation controller in the storyboard? If so, give it a storyboard ID and replace your matchesTVC stuff with the navigation controller.
If matches is a standalone view controller in the storyboard, you can do it in code like this:
let matchesTVC: Matches = self.storyboard?.instantiateViewControllerWithIdentifier("Matches") as! Matches
let navContr = UINavigationController(rootViewController:matchesTVC)
self.presentViewController(navContr, animated: true, completion: nil)
Instantiate the navigation controller that contains your view controller and present the navigation controller.

Issue dismissing Popover presenting another ViewController

I've create a Popover segue in my project and inside a button to when it's touched open another ViewController modally. Then inside the another ViewController I've a button to dismiss the actual ViewController and the Popover too with the following code :
var tmpController :UIViewController! = self.presentingViewController;
self.dismissViewControllerAnimated(true, completion: {()->Void in
println("done");
tmpController.dismissViewControllerAnimated(true, completion: nil);
});
My problem is that when the actual ViewController is dismissed the Popover is like in FullScreen, then it resize to its original size and is dismissed after, and the resize process is animated.
What is causing this behaviour ?
How can I avoid this?
I would suggest you to dismiss the popover view controller from the parent view controller using delegation/notification.