Search code examples
iosswiftside-menu

Side Menu override back button for specific cases


I'm using https://github.com/jonkykong/SideMenu And it's working ok, but, I wan to override the stack.

For example, I have the next flow?:

HomeViewController > MyBusinessViewController > TheBusinessXViewController > Add CategoryViewController > MyBusinessViewController (Again).

But, when I come back to the MyBusinessViewController, the Back Button is redirecting to the previous ViewController, but I want to delete all the stack and have the initial menu there (Like as the HomeViewController) Is that possible?

To have a more natural behavior.


Solution

  • To exclude Add CategoryViewController to the flow, we need considerer this: After the Add CategoryViewController is completed, you want to have: HomeViewController > MyBusinessViewController > TheBusinessXViewController

    TheBusinessXViewController will be the controller to display, then:

    let nextVC = self.storyboard?.instantiateViewController(withIdentifier: "TheBusinessXVC") as! TheBusinessXViewController
            nextVC.id = self.idtruck
            nextVC.extraparameter = "StringOrInt"
    
            let newViewController = self.storyboard?.instantiateViewController(withIdentifier: "HomeVC") as! HomeViewController
            let sencondViewController = self.storyboard?.instantiateViewController(withIdentifier: "MyBusinessVC") as! MyBusinessViewController
    
            let customViewControllersArray : NSArray = [newViewController, sencondViewController, nextVC]
            self.navigationController?.viewControllers = customViewControllersArray as! [UIViewController]
    
            self.navigationController?.pushViewController(nextVC, animated: true)