I've implemented a left side swrevealviewcontroller using storyboard but due to Arabic localization all the labels and icons in side menu goes right but side menu itself remain on left. Is there any chance I can tell revealviewcontroller to be open from right or left programatically?
I tried this line but it won't work:
[self.sidebarButton setAction: #selector( rightRevealToggle: )];
In my splash view controller, I'm creating Reveal View Controller first using storyboard ID
Then I'm creating my side menu view controller using storyboard ID
Then I'm creating my home view controller (Front View Controller) using storyboard ID
Either its Arabic or English front view controller will always be assigned using set Front method of reveal view controller
In the if else clause I'm checking if its English (In my case) I'm adding to right and in case of Arabic I'm adding my side menu to left.
CODE
let revealController = self.storyboard?.instantiateViewController(withIdentifier: "SWRevealViewControllerSBID") as? SWRevealViewController
let rearController = self.storyboard?.instantiateViewController(withIdentifier: "SideMenuVCSBID")
let frontViewController = self.storyboard?.instantiateViewController(withIdentifier: "HomeVCSBID")
let navigationController = UINavigationController.init(rootViewController: frontViewController!)
revealController?.setFront(navigationController, animated: true)
if AppController.sharedInstance.language == "en" {
revealController?.setRight(rearController, animated: true)
} else {
revealController?.setRear(rearController, animated: true)
}
self.present(revealController!, animated: true, completion: nil)
Related
What is the difference between this first call:
let next = self.storyboard?.instantiateViewController(withIdentifier: "AFVC") as! AddFileViewController
self.present(next, animated: true, completion: nil)
and this second:
let dashboard = self.storyboard?.instantiateViewController(withIdentifier: "DBVC") as! DashboardViewController
self.navigationController?.pushViewController(dashboard, animated: true)
The first usage will present the new view controller. This presentation normally slides the new controller up from the bottom. If you want to go back, you need to create a button or something similar to dismiss it.
The second usage will use the navigation controller to display (via push which normally slides in from the right) the new view controller. You will automatically get a "< Back" button in the navigation bar. But this will only work if the calling view controller is already embedded in a navigation controller, otherwise self.navigationController is nil.
I using RWRevealViewController in app. I have a slide menu with couple of cells and each cell is pointed to a viewController. Also, each viewController is embedded in navigationController.
My case is that I have a viewController "A" and viewController "B". If I want to go to any of them, I use the slide menu. However, there is a button in viewController "B" that if I tapped on it, it takes me to viewController "A". In this case, if I want to show viewController "A" with navigation bar and bar button item that shows the slide menu, I used this
let vc = self.storyboard?.instantiateViewController(withIdentifier: "A")
self.present(vc!, animated: true, completion: nil)
This solution works fine if it is in they are in Main storyboard. However, if each one of viewControllers in separate storyboard, I have to specify that storyboard of viewController "A". So, I used this solution
let storyboard = UIStoryboard(name: "A", bundle: nil)
let A = storyboard.instantiateViewController(withIdentifier: "navA")
present(A, animated: true, completion: nil)
In here, The main story board have the container view "SWRevealViewController", slide menu viewController, and a storyboard reference to each viewControllers "A" and "B"
Storyboard name of viewController "A" --> A.storyboard
Storyboard id of navigatoinViewController of viewController "A" --> navA
storyboard reference id of viewController "A" is --> navA
So, when I do that, every thing works except that bar button item does not show the slide menu because revealViewController is equal to nil
The action of bar button item
func sideMenus () {
if revealViewController() != nil {
menuBtn.target = revealViewController()
menuBtn.action = #selector(SWRevealViewController.revealToggle(_:))
revealViewController().rearViewRevealWidth = screenSize.width * 0.75
view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
}
}
How can I fix this?
I am sorry it is to long but excuse me I could not find a shorter way to explain it
Thanks in advance
I have burger button (menu button) in almost all vc and my main screen is tabBarController. Currently I'm getting the side menu when tapping on the Button .On choosing a menu, it shows the desired vc but the bottom tab bar is not there which was there before i select menu item. I want to have the bottom tabbar in entire pages also in pages from the side menu. I.'m using SWRevealViewController for burger menu
How can I acheive this? Please help me.
The code I'm using in didSelectRowAtIndexPath is:
if indexPath.row == 1 {
let destinationVc = self.storyboard?.instantiateViewController(withIdentifier: "Home")
let newFrontVc = UINavigationController.init(rootViewController:destinationVc!)
revealViewController.pushFrontViewController(newFrontVc, animated: true)
}
You have to add tabBarController between navBarVc and frontVc
let navBarVc = UINavigationController()
let tabBarVc = navBarVc.childViewControllers[0] as! tabBarController
tabBarVc.selectedViewController = yourVc
How about that.
I'm using SWRevealController to have a side menu. In my app ,it also have UITabBarcontroller.
My connection format is as SWRevealViewController--->UItabbarController--->NavigationController--->UITabbaritemPage-->Another vc
PLEASE CLICK ON THE IMAGE TO SEE IN CORRECT ORIENTATION
The above show is the layout I'm using.I want to have that burger button (menu button) in almost all vc that are showing from and in tabbarcontroller. Currently I'm getting the side menu when tapping on the Button (The image showed in right side as spereate).On choosing a menu, it shows the desired vc but,the bottom tab bar is not there. I want to have the bottom tabbar in entire pages also in pages from the side menu.
How can I acheive this? Please help me.
The code I'm using in didSelectRowAtIndexPath is:
if indexPath.row == 1{
let destinationVc = self.storyboard?.instantiateViewController(withIdentifier: "Home")
let newFrontVc = UINavigationController.init(rootViewController:destinationVc!)
revealViewController.pushFrontViewController(newFrontVc, animated: true)
}
I think you don't actually need to push a view controller if using tab bar controller.
let tabBarController = self.storyboard?.instantiateViewController(withIdentifier: "TabBarController")
tabBarController.selectedIndex = 1
revealViewController.pushFrontViewController(tabBarController, animated: true)
You would have to set the identifier of the tab bar controller to be TabBarController in Main.storyboard for this to work.
I also had the same layout like you only few view controllers has been added to the tabbar and it will show the tab bar in all view controllers
SWRevealViewController with TabBarController using XIB in Swift 4
let objSideBarVC = SideBarVC(nibName: "SideBarVC", bundle: nil)
let navSidebar = UINavigationController(rootViewController: objSideBarVC)
navSidebar.navigationBar.isHidden = true
let objDashboardVC = DashboardVC(nibName: "DashboardVC", bundle: nil)
let navDashboard = UINavigationController(rootViewController: objDashboardVC)
navDashboard.navigationBar.isHidden = true
let mainRevealController = SWRevealViewController.init(rearViewController: navSidebar,frontViewController: navDashboard)
AppDelegate().window?.rootViewController = mainRevealController
mainRevealController.pushFrontViewController(TabBarController, animated: true)
I'm currently writing an app where we are launching a walkthrough the first time the user opens the app. At the end of it, we require the user to fill in a few details, and to do so I would like him to press a button to get redirected to the settings page.
The thing is, this page is one level down the navigation controller (from the landing page). As it stands, I can correctly instantiate the landing page, but the redirection to the settings page never happens.
let mainView = self.storyboard?.instantiateViewControllerWithIdentifier("NavCtrl")
self.presentViewController(mainView!, animated: false, completion: nil)
// the above works correctly and sends us to the landing screen
// (rootView of the navigation controller)
// the following lines never have any effect though
let settingsView = self.storyboard?.instantiateViewControllerWithIdentifier("Settings View")
self.navigationController?.pushViewController(settingsView!, animated: false)
I think it's because I'm trying to call .pushViewController before the storyboard had time to instiate either the first or second view.
So I have a few questions:
Is there a way to, indeed, instantiate a view and then navigate to another one right after it has been instantiated ? (this in order to keep the navigation stack and maintain accurate nav bar behaviour)
If there isn't, would it be possible to programmatically populate the navigation stack so that I would only need to instantiate the settings view ? This in order to still have the back button in the nav bar that would send to the landing screen ?
Thanks in advance guys
Ok thanks to #Leonardo for showing me the correct direction !
I solved the issue by doing the following in appDelegate:
/*
* Override window root view and set it to a newly initialized one
* view: StoryboardID of view to display
* navigateTo: if true, set the root view to NavCtrl and then navigate to the desired view
*/
func setWindowViewTo(view: String, navigateTo: Bool) {
//initalize storyboard & window programmatically
window = UIWindow.init(frame: UIScreen.mainScreen().bounds)
let storyboard = UIStoryboard(name: "Main", bundle: nil)
//if true, navigate from landing page to specified view through navigationController
if(navigateTo) {
//instantiate the navigation controller
let navCtrl = storyboard.instantiateViewControllerWithIdentifier("NavCtrl") as! UINavigationController
//instantiate the landing page & the page we wish to navigate to
let landingView = storyboard.instantiateViewControllerWithIdentifier("Main View")
let vc = storyboard.instantiateViewControllerWithIdentifier(view)
//manually set the navigation stack to landing view + view to navigate to
navCtrl.setViewControllers([landingView, vc], animated: false)
//replace the rootViewController to the navigation controller
window!.rootViewController = navCtrl
//make it work
window!.makeKeyAndVisible()
} else {
window!.rootViewController = storyboard.instantiateViewControllerWithIdentifier(view)
window!.makeKeyAndVisible()
}
}
The important step was to indeed force downcast as! UINavigationController when instantiating the NavigationController with the storyboard.instantiateViewControllerWithIdentifier() method.
Then it's just a case to correctly instantiate the views of the navigation stack you want, and finally calling navCtrl.setViewControllers([view1, view2], animate: false).
Thanks all for your help !
You can use the - setViewControllers:animated: method to set the navigation stack of a UINavigationController
Here's the reference
But I don't think that's your problem, if I undestood your code correctly, it should be
//This is the navigation controller
if let mainView = self.storyboard?.instantiateViewControllerWithIdentifier("NavCtrl"){
//Nav being modally presented
self.presentViewController(mainView, animated: false, completion: nil)
// Instantiate the settings view
if let settingsView = self.storyboard?.instantiateViewControllerWithIdentifier("Settings View"){
//Push it to the navigation controller presented
mainView.pushViewController(settingsView, animated: false)
}
else{
//Can't Instantiate, deal with error
}
}
else{
//Can't Instantiate, deal with error
}