dekatotoro / SlideMenuControllerSwift

iOS Slide Menu View based on Google+, iQON, Feedly, Ameba iOS app. It is written in pure swift.
MIT License
3.4k stars 755 forks source link

Slide Menu not pulling up on main page after present/dismiss of another view #68

Closed Jthami05 closed 8 years ago

Jthami05 commented 8 years ago

The entry point/initial view controller in my app is a TableViewController that presents a LogInViewController if not logged in, and dismisses it once the login succeeds. I'm using NSUserDefaults for the log in status (just a Bool returning true if logged in) for now. So when I open the app with it logged in, go to log out, and log back in, the slide menu won't come up on the TableViewController, either through the BarButtonItem or through dragging the screen from the side.

I'm not sure what's causing this, or even what code to show that's relevant to the issue. I was calling setNavigationBarItem() within viewDidAppear() in my TableViewController, but am now calling it in viewWillAppear() because using viewDidAppear() completely prevents the navigation bar from showing up on my TableView page. My TableViewController is a child of a NavigationController, and my LogInViewController isn't, it just segues directly to the TableViewController. I'm also noticing that viewWillAppear() is being called twice and haven't found a way to prevent that online, and am not sure if it's related to the fact that the slide menu isn't showing up once I log back in.

The code I'm using to present (from TableViewController.swift) and dismiss(from LogInViewController.swift) is:

let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let vc = storyboard.instantiateViewControllerWithIdentifier("LogInViewController") as! LogInViewController
let navigationController = UINavigationController(rootViewController: vc)
    self.presentViewController(navigationController, animated: false, completion: nil)

and self.dismissViewControllerAnimated(true, completion: nil)

I don't know how much of this issue is on my end or if it's just something this library isn't designed to do. Please let me know if any more code would be helpful in solving this problem.

sairamkotha commented 8 years ago

I am facing same issue..Did u solve this issue?

Jthami05 commented 8 years ago

@salramkotha, sorry to get to you late. If you're still having the problem, I believe I managed to fix it by inserting

dispatch_async(dispatch_get_main_queue(), {
               let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
                appDelegate.createMenuView()
                })

inside my LogInViewController.swift's if (success for login condition) { } check, immediately after dismissing the view controller (also within the if block). It might be messy or non-ideal, but it gets the job done.

sairamkotha commented 8 years ago

in app delegate createmenuview() can u share code of create menu view I am using view in view controller how to activate that viewcontroller?

Jthami05 commented 8 years ago
func createMenuView() {
let storyboard = UIStoryboard(name: "Main", bundle: nil)

    let leftViewController = storyboard.instantiateViewControllerWithIdentifier("LeftViewController") as! LeftViewController
    let tableViewController = storyboard.instantiateViewControllerWithIdentifier("TableViewController") as! TableViewController
    let nvc: UINavigationController = UINavigationController(rootViewController: tableViewController)

    leftViewController.homeViewController = nvc

    let slideMenuController = SlideMenuController(mainViewController: nvc, leftMenuViewController: leftViewController) // SlideMenuController.mainViewController is the entry point.

    self.window?.rootViewController = slideMenuController
    self.window?.makeKeyAndVisible()
}

It should be roughly the same as what's given by dekatotoro, except with a navigationController containing the tableViewController. So the first parameter of SlideMenuController is that navigationController.

sairamkotha commented 8 years ago

Thank you. will try this :)