Swipe Right to Dismiss ViewControlelr without using Storyboard Swift

1.8k Views Asked by At

How to dismiss any View Controller without using Storyboard ? and do I have to use UINavigationController to achieve this ? if not how then ?

3

There are 3 best solutions below

4
swift taylor On BEST ANSWER

The way to dismiss a view controller is to call a dismiss method on the presenting view controller. If you presented your child controller from a parent by calling self.present(_:animated:) then you can call self.dismiss(animated:). If you used a navigationController and called navigationController.push(_:animated:) then you need to tell the navigation controller to dismiss with navigationController.popViewController(animated:) Method names might not be exact, but you should be able to figure it our with autocomplete.

0
Matias Jurfest On

If you want to swipe right is not a dismiss, but I think that what you want it to embed the UIViewController inside a UINavigationController.

For example:

if let vc = UIStoryboard(name: "YourStoryboard", bundle: nil).instantiateViewController(withIdentifier: "YourViewController") as? YourViewController {
  let navigation = UINavigationController(rootViewController: vc)
  navigationController?.pushViewController(vc, animated: true)
}
0
Abdul Saboor On

if someone is still struggling to dissmiss on swipe (left,right,bottom,top) i came across a very elegant and decent cocapod panslip

with a very simple usage

just call this method in viewDidLoad()

For viewController embedded in navigation Controller

let viewControllerVC = self.navigationController

    viewControllerVC!.ps.enable(slipDirection: .leftToRight){
        
        //anything you want to do after dissming
        
    }

For Simple View Controller

let viewControllerVC = self

    viewControllerVC!.ps.enable(slipDirection: .leftToRight){
        
        //anything you want to do after dissming
        
    }

For TableView embedded in View Controller

let viewControllerVC = self.YourTableview.parentContainerViewController()

    viewControllerVC!.ps.enable(slipDirection: .leftToRight){
        
        //anything you want to do after dissminn
        
    }