Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing root of SlideMenuController #267

Closed
iOS-Ahytech opened this issue Dec 24, 2016 · 10 comments
Closed

Changing root of SlideMenuController #267

iOS-Ahytech opened this issue Dec 24, 2016 · 10 comments

Comments

@iOS-Ahytech
Copy link

iOS-Ahytech commented Dec 24, 2016

I'm using this SlideMenuController. But I want it to start from my ShopHome screen. And in my app my root/initial VC is Login page. When I use the below code it goes directly to ShopHome. But instead I want my app to start from Login and then menu on ShopHome screen. I tried changing root to my LoginVC but then menu doesn't work when I'm on ShopHome page.

let mainViewController = storyboard.instantiateViewController(withIdentifier: "ShopHomeVC") as! ShopHomeVC
let rightViewController = storyboard.instantiateViewController(withIdentifier: "RightMenuVC") as! RightMenuVC
let nvc: UINavigationController = UINavigationController(rootViewController: mainViewController)

let slideMenuController = SlideMenuController(mainViewController: nvc, rightMenuViewController: rightViewController)
self.window?.rootViewController = slideMenuController
self.window?.makeKeyAndVisible()`
@kamirana4
Copy link

kamirana4 commented Dec 24, 2016

In AppDelegate, add LoginVC as something like below,

let loginVC = storyboard.instantiateViewController(withIdentifier: "LoginVC") as! LoginViewController
self.window?.rootViewController = loginVC
self.window?.makeKeyAndVisible()

Then on the tap of Login Button in the LoginVC, add this

@IBAction func loginButtonAction(_ sender: Any) {
let mainViewController = storyboard.instantiateViewController(withIdentifier: "ShopHomeVC") as! ShopHomeVC
let rightViewController = storyboard.instantiateViewController(withIdentifier: "RightMenuVC") as! RightMenuVC
let nvc: UINavigationController = UINavigationController(rootViewController: mainViewController)

let slideMenuController = SlideMenuController(mainViewController: nvc, rightMenuViewController: rightViewController)
UIApplication.shared.delegate?.window?.rootViewController = slideMenuController
}

@iOS-Ahytech
Copy link
Author

@kamirana4 Thanks this solved my problem. And Can you help me in decreasing width of menu ?

@kamirana4
Copy link

kamirana4 commented Dec 24, 2016

Yes, you can set any width of the sliding menu. You can play with these configurations in your AppDelegate,

SlideMenuOptions.animationDuration = 0.2
SlideMenuOptions.hideStatusBar = true
SlideMenuOptions.contentViewScale = 1.0
SlideMenuOptions.leftViewWidth = self.window?.screen.bounds.size.width * 0.72
SlideMenuOptions.rightViewWidth = self.window?.screen.bounds.size.width * 0.65

@iOS-Ahytech
Copy link
Author

@kamirana4 It worked. Thanks for helping me out.

@iOS-Ahytech
Copy link
Author

@kamirana4 Hi, I have one problem with this. When user is at login screen and if he swipe from corner then Menu appears. I don't want them to appear unless he logged in. I haven't added the button on viewDidAppear but still on swiping through corner, the menu appears.

@iOS-Ahytech iOS-Ahytech reopened this Dec 28, 2016
@kamirana4
Copy link

kamirana4 commented Dec 28, 2016

@iOS-Ahytech Use below methods to control the side menu appearance,

self.slideMenuController()?.removeLeftGestures() to disable
self.slideMenuController()?.addLeftGestures() to enable

Try above in viewWillAppear and viewWillDisappear

@sarathdev
Copy link

sarathdev commented Jul 27, 2017

@kamirana4 Hi, I'm using SlideBar controller in my app and I want to reload the same page with different data. But my problem is if I load one view the second time, The view did load is not calling. Is there any way to load the view did load method whenever we navigating to the view from slide bar?

@kamirana4
Copy link

kamirana4 commented Jul 27, 2017

@sarathdev Although there are many ways to reload view's with new data. Because i don't know the exact implementation of the ViewController you are trying to update the view with new data.

can you try self.slideMenuController()?.mainViewController = yourViewController when you have new data.

@sarathdev
Copy link

@kamirana4
HI I was using this instead of the method u mentioned self.slideMenuController()?.changeMainViewController(self.productListViewController, close: true).
But when I use the new one u mentioned above, nothing is happening for me it's not loading the view

@sarathdev
Copy link

My problem is When I'm loading from one of my section from the left menu. It will load the same view controller repeatedly. But according to the row, I clicked the data and the API call should be different so for archiving that I need to hit the view did load when it navigates from the side menu bar. Here only the first case view did load is calling in all other all cases its only hitting view did appear or view will appear, But if I hit API in view did appear again it will be issue when I got a detail page and come back

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants