2015-04-19 67 views
2

我正在使用MMDraweController。它工作完美。我有rootViewController的問題。當應用程序啓動時,它加載loginViewController。所以我不想要側欄菜單那裏(loginViewController沒有任何導航控制器)。我的問題是使用下面的代碼應用程序從viewController開始,而不是loginViewController。我怎樣才能使用登錄頁面沒有側欄菜單和viewController邊欄?swift MMDrawerController:想改變rootViewController

var rootViewController = self.window!.rootViewController 

     let mainStoryBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil) 

     var centerViewController = mainStoryBoard.instantiateViewControllerWithIdentifier("ViewController") as ViewController 
     //var rootViewController = centerViewController 

     var leftViewController = mainStoryBoard.instantiateViewControllerWithIdentifier("SideBarMenuViewController") as SideBarMenuViewController 
     var leftSideNav = UINavigationController(rootViewController: leftViewController) 
     var centerSideNav = UINavigationController(rootViewController: centerViewController) 

     centerContainer = MMDrawerController(centerViewController: centerSideNav, leftDrawerViewController: leftSideNav) 


     centerContainer!.openDrawerGestureModeMask = MMOpenDrawerGestureMode.PanningCenterView 
     centerContainer!.closeDrawerGestureModeMask = MMCloseDrawerGestureMode.PanningCenterView 

     window!.rootViewController = centerContainer 
     window!.makeKeyAndVisible() 
+0

我試圖改變窗口!.RootViewController = loginViewController但它給了我一個錯誤 –

+0

發現任何解決方案? –

+0

是的,一分鐘我會把答案 –

回答

1

當加載loginPageViewController只要把下面這行代碼:

var appDelegate: AppDelegate = UIApplication.sharedApplication().delegate as AppDelegate 

    appDelegate.centerContainer!.openDrawerGestureModeMask = MMOpenDrawerGestureMode.None 
+0

把它放到viewdidload方法 –

+0

看看我的問題...你有同樣類型的問題..... http://stackoverflow.com/questions/29944715/set-up-side-drawer-controller或故事板位置 –

+0

遐我把它放在viewdidload中,但它仍然去viewcontrolled insted登錄....我只是改變代碼與您的問題代碼....請幫助我哥們...有一個相同的情況 –

0

爲時已晚,但可能幫助別人......

我通過創建的AppDelegate功能解決了這樣的問題。 swift

func goToMainVC() { 
    var rootViewController = self.window!.rootViewController 
    let mainStoryBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil) 

    var centerViewController = mainStoryBoard.instantiateViewControllerWithIdentifier("ViewController") as ViewController 
    //var rootViewController = centerViewController 

    var leftViewController = mainStoryBoard.instantiateViewControllerWithIdentifier("SideBarMenuViewController") as SideBarMenuViewController 
    var leftSideNav = UINavigationController(rootViewController: leftViewController) 
    var centerSideNav = UINavigationController(rootViewController: centerViewController) 

    centerContainer = MMDrawerController(centerViewController: centerSideNav, leftDrawerViewController: leftSideNav) 
    centerContainer!.openDrawerGestureModeMask = MMOpenDrawerGestureMode.PanningCenterView 
    centerContainer!.closeDrawerGestureModeMask = MMCloseDrawerGestureMode.PanningCenterView 

    window!.rootViewController = centerContainer 
    window!.makeKeyAndVisible() 
} 

然後在登錄完成後調用此函數或另一個ViewController像這樣

let appDelegate = UIApplication.shared.delegate as! AppDelegate 
appDelegate.goToMainVC() 

就是這樣!