0

I'm using SWRevealViewController for SideMenu bar option on HomeVC of my app.

When user taps on any button present in HomeVC it navigates to another screen (PushViewController). In this new view controller I've shown custom back button.

Now, when user taps on this back button the view should get poped to HomeVC. Below is code that I've used:

HomeViewController :

@IBAction func recharge_Mobile(_ sender: UIButton) {

   let objRechargeMobileViewController = self.storyboard?.instantiateViewController(withIdentifier: "idRechargeMobileViewController") as! RechargeMobileViewController
   self.navigationController?.pushViewController(objRechargeMobileViewController, animated: true)
    }

RechargeViewController :

     override func viewDidLoad() {
            super.viewDidLoad()

            self.navigationItem.leftBarButtonItem = UIBarButtonItem(image:UIImage(named:"back.png"), style: .plain, target: self, action: #selector(btnBack_Clicked()))

            self.navigationController?.navigationBar.tintColor = UIColor.black
  . . .   
  }

     @IBAction func btnBack_Clicked() {
           /* for controller in self.navigationController!.viewControllers as Array {
                if controller.isKind(of: ViewController()) {
                    self.navigationController?.popToViewController(controller as! ViewController, animated: true)
                    break
                }
            } */

            self.navigationController?.popViewController(animated: true)
        }

Where I'm going wrong?

Jayprakash Dubey
  • 35,723
  • 18
  • 170
  • 177

0 Answers0