John-Lluch / SWRevealViewController

A UIViewController subclass for presenting side view controllers inspired on the FaceBook and Wunderlist apps, done right !
Other
4.52k stars 987 forks source link

How to go back from ViewController3 to ViewController2 or previous VC? #606

Open SuYungCheng opened 8 years ago

SuYungCheng commented 8 years ago

My left menu has 3 items(VC1,VC2,VC3). If now I go to VC3 from VC2 by tapping the third item in left menu , then StoryBoard use "SWRevealViewControllerSeguePushController" push to VC3. How can I create a Custom "Back Button" in VC3 , and make the view back to previous VC?

I don't want to use this code:

let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let VC = storyboard.instantiateViewControllerWithIdentifier("FirstViewControllerID")
        self.presentViewController(VC, animated: true, completion: nil)

Because I don't know how to get my previous VC's ID Thank you so much!

iDevelopper commented 8 years ago

If you want a back button your controller must be pushed by a navigation controller.

You can do this:

let frontVC = self.revealViewController().frontViewController as? UINavigationController push it with SW: self.revealViewController().pushFrontViewController(frontVC, ...) and push the selected one with with the navigation controller: frontVC.pushViewController...

errabelli09 commented 8 years ago

Can you tell the code in objective c

iDevelopper commented 8 years ago
UINavigationController` *frontVC = (UINavigationController *)self.revealViewController.frontViewController;
[self.revealViewController pushFrontViewController:frontVC animated:YES];
[frontVC pushViewController: yourVC animated:YES];
errabelli09 commented 8 years ago

Thanks a lot saving my day