Link Openheim Link Openheim - 4 months ago 36
iOS Question

Swift - SWRevealViewController Left BarButtonItem not working after navigation

I have implemented SWRevealViewController into my project successfully. The side menu is a UITableView with different cells which navigate to differing view controllers. When I tap on the 'profile' cell it defaults to the LoginViewController, there the user will login in and, once verified, will go to the ProfileViewController. This leads to my problem, when I navigate to the ProfileViewController the Navigation bar button (on the left) does not work properly. Likewise, when I press the logout button (the right navigation bar button) it does navigate back to the LoginViewController, however, the menu button does not work.

My navigation functions are as follows:

func switchVC() { //Navigates to the profileViewController
let storyboard = UIStoryboard.init(name: "Login", bundle: nil)
let nav = storyboard.instantiateViewControllerWithIdentifier("Profile")
UIApplication.sharedApplication().keyWindow?.rootViewController = nav
}

func switchBack() { //Navigates back to the LoginViewController
let storyboard = UIStoryboard.init(name: "Login", bundle: nil)
let nav = storyboard.instantiateViewControllerWithIdentifier("Login")
UIApplication.sharedApplication().keyWindow?.rootViewController = nav
}


My storyboard is as follows: Storyboard

Any help that you may be able to provide would be greatly appreciated. Thank you everyone!

Cheers

Answer

Your question is somewhat difficult to answer, but maybe this will help. In order for SWReveal View Controller to work, you always have to route to the main SWReveal Controller Scene for the menu button to work. For example, if my storyboard looked like

SWRevealViewController Scene --> Navigation Controller Scene --> Main View

and I routed back to the Navigation Controller Scene, the button would not work. You have to route back to the first Instance of the SWRevealController Scene that comes before the navigation / any other scenes you are trying to reach.

If you need to add another instance of SWRevealViewController Scene to make that work, just segue through the sw_front identifier to the navigation controller/ view controller you need the button to work in, and then segue it through the sw_rear identifier back to the same one instance of the menu.

Sorry if this answer is confusing, please let me know if I can clarify anything.