-1

i'm new in ios development.

I use SWRevealViewController to add back side menu in my app. I want to add back button to each view in Menu. When I tap on the back button, I want to always go to initial(MainTabbedView) view.

Ui flow :

-->MainTabbedVIew-->(toggle_menu)-->(select Item1)-->Item 1-->(Back pressed)-->MainTabbedView

I found a similar question , ios SWRevealViewController pop from rear to front, but it is still has no answer.

I added a button to view and write some code :

@IBAction func backPressed(sender: UIBarButtonItem) {
    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let vc = storyboard.instantiateViewControllerWithIdentifier("mainTabbedScreen") as UIViewController!
    self.revealViewController().pushFrontViewController(vc, animated: true)
}

It works, but controller always recreated, for example: in TabBarController selected tab always resets.

I want to add NavigationController behavior(pop previous view) to SWRevealViewController menu items.

My storyboard: https://i.stack.imgur.com/MW4Rw.png

Michael
  • 32,527
  • 49
  • 210
  • 370

1 Answers1

0

I found solution. In my application , I began to use MMDrawerController instead of SWRevealViewController I use UINavigationController as central ViewController , and when Menu click occurs id call

pushViewController(controller,animated: true)

my AppDelegate:

class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?
var backSideController:MMDrawerController?
var roorNavigationController:UINavigationController?


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.
    var rootController = self.window!.rootViewController
    let storyBoard : UIStoryboard = UIStoryboard(name:"Main",bundle:nil);
    var centerContent = storyBoard.instantiateViewControllerWithIdentifier("Center") as! UIViewController
    var left = storyBoard.instantiateViewControllerWithIdentifier("Left") as! Left
    var right = storyBoard.instantiateViewControllerWithIdentifier("Right") as! Right
    roorNavigationController = UINavigationController(rootViewController: centerContent)
    backSideController = MMDrawerController(centerViewController: roorNavigationController, leftDrawerViewController: left,rightDrawerViewController: right)
    backSideController!.openDrawerGestureModeMask = MMOpenDrawerGestureMode.PanningCenterView

    backSideController!.closeDrawerGestureModeMask = MMCloseDrawerGestureMode.PanningCenterView
    window!.rootViewController=backSideController
    window!.makeKeyAndVisible()
    return true
}
func pushController(controller: UIViewController){
    self.roorNavigationController?.pushViewController(controller,animated: true)
    self.backSideController!.toggleDrawerSide(MMDrawerSide.Left, animated: true, completion: nil)
}

And somewhere in MyMenuController :

@IBAction func pressed(sender: UIButton) {
    var newController = self.storyboard?.instantiateViewControllerWithIdentifier("About") as! About
    var appDelegate:AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
    appDelegate.pushController(newController)

}