I am trying to use the third party SlideMenuControllerSwiftfor displaying a hamburger menu. I am able to display the hamburger menu properly when it is loaded in the very first viewcontroller that comes up. But in case I have a login screen for example and after the login screen, I navigate to another screen and when I try to show the slide menu in this screen, I am not able to do so properly.
In the example from github for SlideMenuControllerSwift, the required screens are loaded in the AppDelegate and called in the AppDelegate itself from didFinishLaunchingWithOptions. Following this idea, even if I call the method that is called in didFinishLaunchingWithOptions from the viewDidLoad of my screen of choice (where I want to display the hamburger menu), the hamburger menu is not showing up in that screen. I do get the logo of the hamburger menu displayed on top left but it is not clickable. Please help...:)
When user login try this.
SlideMenuOptions.contentViewDrag = true
SlideMenuOptions.leftViewWidth = self.view.frame.size.width * 0.75
let contentVC = self.storyboard?.instantiateViewController(withIdentifier: "HomeViewController") as! HomeViewController
let leftVC = self.storyboard?.instantiateViewController(withIdentifier: "LeftViewController") as! LeftViewController
let slideVC = SlideMenuController(mainViewController: contentVC, leftMenuViewController: leftVC)
slideVC.view.clipsToBounds = true
self.navigationController?.pushViewController(slideVC, animated: true)
Replace pushViewController with PresentViewController ,
let rootController = UIStoryboard.init(name:"Main", bundle: nil).instantiateViewController(withIdentifier:"HomeVC") as! HomeViewController
SlideMenuOptions.leftViewWidth = 280.0
SlideMenuOptions.contentViewScale = 1.0
let leftMenu = UIStoryboard.init(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "slidingMenuNavigationController") as! UINavigationController
let slideMenuController = SlideMenuController(mainViewController: rootController, leftMenuViewController: leftMenu)
present(slideMenuController, animated: true, completion: nil)
Related
I've following view configuration
Tab bar -> Nav controller -> View: Click on a button -> segue to-> Another view: Click on a button -> Popup view.
This modal view is on a different storyboard.
I want to present this model view in full screen. I've tried this solution mentioned on Presenting modal in iOS 13 fullscreen but it doesn't work. I've also tried few other solutions but the popup view is not showing over full screen, status bar is visible at the top.
How do I present modal view in a full screen?
let storyboard = UIStoryboard(name: "Other", bundle: Bundle.main)
guard let popupVC = storyboard.instantiateViewController(withIdentifier: "PopUpViewController") as? PopUpViewController else {
print("PopUpViewController not found")
return
}
popupVC.modalPresentationStyle = .fullScreen
self.present(popupVC, animated: true, completion: nil)
You could try presenting with the navigation controller.
let storyboard = UIStoryboard(name: "Other", bundle: Bundle.main)
guard let popupVC = storyboard.instantiateViewController(withIdentifier: "PopUpViewController") as? PopUpViewController else {
print("PopUpViewController not found")
return
}
var navigationController = UINavigationController(rootViewController: popupVC)
navigationController.modalPresentationStyle = .fullScreen
self.present(navigationViewController, animated: true, completion: nil)
An alternative would be to use presentViewController but presentViewController will only present one viewController modally over the currently visible viewController whereas presenting with the navigationController will give the flexibility to push further components on top, providing a smoother navigation experience with go back to previous page kind of behaviour.
Maybe try creating the view controller this way:
let popOverVC = UIStoryboard(name: "yourBoard", bundle: nil).instantiateViewController(withIdentifier: "YourViewController") as! YourViewController
self.addChild(popOverVC)
let lSs = UIScreen.main.bounds
popOverVC.view.frame = CGRect(x: 0, y: 0, width: lSs.width, height: lSs.height)
popOverVC.view.tag = tag
self.view.addSubview(popOverVC.view)
popOverVC.didMove(toParent: self)
Within the popup view controller class, add a method for animating its view in viewDidLoad.
Edit: I read your replies. The issue you are having is caused by not handling the status bar properly. Instead of trying to make this veiewcontroller fullscreen, simply hide the status bar
How do I hide the status bar in a Swift iOS app?
and bring it back when you want to see it again.
I am setting up the side menu by following SideMenu
When the app is loaded first the side menu controller is working fine (.menuslide)
but when I come back to the same controller from the side menu to the same view controller or any other controller or any other page it is not following (.menuslide)
I have tried by assigning the navigation
let menu = SideMenuNavigationController(rootViewController: YourViewController)
let rightMenuNavigationController = SideMenuNavigationController(rootViewController: YourViewController)
SideMenuManager.default.rightMenuNavigationController = rightMenuNavigationController
present(menu, animated: true, completion: nil)
through code and also
From the story board
I am navigating from every controller to side menu like this
let navigationController = storyboard!.instantiateViewController(withIdentifier: "sidemenunavigation") as! SideMenuNavigationController present(navigationController, animated: true, completion: nil)
for the first time after loading it is navigating properly (.menuslide)
but after navigating to other controller and get the side menu it is not following (.menuslide)
you may use the following RESideMenu for side menu quite easy to use
RESideMenu for side menu
please check this code is working fine for navigation another view controller for sidemenu
let storyBoard = UIStoryboard(name:"Main", bundle: nil)
if let conVC = storyBoard.instantiateViewController(withIdentifier: "RoutingAddViewController") as? RoutingAddViewController,
let navController = UIApplication.shared.keyWindow?.rootViewController as? UINavigationController {
navController.pushViewController(conVC, animated: true)
}
First of all, let me introduce what I'm trying to do. Second... I'm new to Swift/iOS development.
What I'm trying to do is:
When I open the APP, it loads the LoginVC. When the user logs in, the TableSelectionVC loads. If the user selects a cell, it goes to the Home screen with the selected values. If the user taps on the bell (blue arrows) the app should go to AlarmVC.
It should work, but it doesn't. The AlarmVC says that self.revealViewController() is nil. BUT If I go to alarmVC through the menu option (red arrows) it loads normally and the Menu is shown. Also, if I choose the option in green, it goes to the TableSelectionVC and if I tap the icon, it goes to alarmVC and it doesn't crash. The problem is if I go from LoginVC to TableSelectionVC and tap on the icon, the it will crash.
I think it is the way that I'm setting the views, instantiating a controller and setting the window.rootViewController.
In my AppDelegate I have the following functions:
func changeRootViewControllerToSWRevealViewController () {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: "SWRevealViewController")
controller.modalTransitionStyle = .flipHorizontal
if let window = self.window {
window.rootViewController = controller
}
}
func changeRootViewControllerToPlantSelectionVC () {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: "navPlantSelectionVC")
controller.modalTransitionStyle = .flipHorizontal
if let window = self.window {
window.rootViewController = controller
}
}
When the user logs in the app, the following function is executed:
static func goToPlantSelection() {
guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else {
//there should be an alert error
return
}
appDelegate.changeRootViewControllerToPlantSelectionVC()
}
After that, the PlantSelectionVC is shown and if the user taps on an cell the appDelegate.changeRootViewControllerToSWRevealViewController() is executed and the HomeVC is shown.
If the user taps on the icon, it tries to go to the AlarmVC but it crashes, like I said. I think I'm doing something wrong with binding the SWRevealViewController with LoginVC and TableSelectionVC.
The following code in AlarmVC tries to execute:
static func setupMenuToggle(button: UIBarButtonItem, viewController: UIViewController) {
button.target = viewController.revealViewController()
viewController.revealViewController().rearViewRevealWidth = viewController.view.bounds.size.width * 0.9
button.action = #selector(SWRevealViewController.revealToggle(_:))
}
But is shows the error in the third line: found nil while unwrapping an Optional value
Can anyone help ?
I fixed it. I set the login screen as sw_front for the swRevealViewController and after that, when the user logs in I would change the swRevealViewController front view controller with
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: "navPlantSelectionVC")
self.revealViewController().setFront(controller, animated: true)
It is working now.
swift3, xcode8 ios
I'm creating an app that calls a button on a widget to show a specific page in App
For example, an app consists of viewA and viewB, and the first view is viewA
I'm trying to show viewB when I press a button in a widget.
Source
let mainStoryboard: UIStoryboard = UIStoryboard (name: "Main", bundle: nil)
let DetailView: Detail_Update_View = mainStoryboard.instantiateViewController(withIdentifier: "Detail_Update_View") as! Detail_Update_View
let nav2 = UINavigationController.init (rootViewController: DetailView)
self.window?.rootViewController? .present (nav2, animated: true, completion: nil)
This is called from the func open url in AppDelegate.
When you click on a button in the widget, viewB is called initially.
Open the widget again and press the button
The page will be called but the information will not change and the following error will be displayed
errorMessage
Warning: Attempt to present <UINavigationController: 0x101a1b600> on <SWRevealViewController: 0x101820c00> whose view is not the window hierarchy!
If you make a first call to the widget, close the viewB screen (go to viewA) and click the button in the widget to get it working.
please help me..
let mainStoryboard: UIStoryboard = UIStoryboard (name: "Main", bundle: nil)
let DetailView: Detail_Update_View = mainStoryboard.instantiateViewController(withIdentifier: "Detail_Update_View") as! Detail_Update_View
let nav2 = UINavigationController.init (rootViewController: DetailView)
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.window?.rootViewController?.present (nav2, animated: true, completion: nil)
in my app delegate this is how I navigate to my SWRevealViewController
let revealViewController = mainStoryboard.instantiateViewControllerWithIdentifier("RevealView") as? SWRevealViewController
self.window!.rootViewController = revealViewController
self.window?.makeKeyAndVisible()
I navigate to that inner view controller from the SWRevealViewController's FrontViewcontrollerlike this.
let secondViewController = self.storyboard?.instantiateViewControllerWithIdentifier("Read") as! ReadViewController
secondViewController.title = self.selectedTitle
self.navigationController?.pushViewController(secondViewController, animated: true)
Now in AppDelegate when receive a push notification I want to navigate this ReadViewController. and when I click the back button it should come back to the FrontViewController just like it happens in normal way. How can I do this in my notification delegates in AppDelegate
Please help me.
Thanks
Try this :
let yourVC = mainStoryboard.instantiateViewControllerWithIdentifier("Read") as! ReadViewController
let frontViewController = mainStoryboard.instantiateViewControllerWithIdentifier("frontViewController") as! FrontViewController
let navController = UINavigationController()
navController.viewControllers = [yourVC,frontViewController]
self.window!.rootViewController = navController
self.window?.makeKeyAndVisible()