如何向SWRevealViewController中的所有菜单项添加后退按钮,该按钮将弹出到前视图

时间:2015-05-16 15:21:57

标签: ios swift swrevealviewcontroller

我是ios开发的新手。

我使用SWRevealViewController在我的应用程序中添加背面菜单。 我想在菜单中为每个视图添加后退按钮。 当我点击后退按钮时,我想总是转到初始(MainTabbedView)视图

Ui flow:

- > MainTabbedVIew - > (toggle_menu) - > (选择项目1) - >项目1 - > (后退) - > MainTabbedView

我发现了一个类似的问题ios SWRevealViewController pop from rear to front,但它仍然没有答案。

我添加了一个按钮来查看和编写一些代码:

@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)
}

它可以工作,但控制器总是重新创建, 例如:在TabBarController中选中的选项卡总是重置。

我想将NavigationController行为(弹出上一个视图)添加到SWRevealViewController菜单项。

我的故事板: http://i.imgur.com/kf5TlAR.png?1

1 个答案:

答案 0 :(得分:0)

我找到了解决方案。 在我的应用程序中,我开始使用MMDrawerController而不是SWRevealViewController 我使用UINavigationController作为中央ViewController,当菜单点击发生id调用

pushViewController(controller,animated: true)

我的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)
}

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)

}