On selecting menu Item from the side menu TabBar gets disappear? - ios

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.

Related

revealViewController is nil when I segue between one viewController to another in different storyboard

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

Swift How to present Tabbar on Button click

In my project i want to present Tabbar on button click, now i have already created tabbar and i give identity name as "tabbar" that i show you in below image
so now i am using below code to call Tab bar controller but i am not getting it.
let tabbar: UITabBarController? = (storyboard.instantiateViewController(withIdentifier: "tabbar") as? UITabBarController)
navigationController?.pushViewController(tabbar, animated: true)
can you guys suggest me what i need to do and which code is useful to me to present Tabbar controller.
For more specification : i added below image in which there is blue button in one viewController i want to present tab bar controller on click of that blue button
Thank you.
Try this and see:
Using Storyboard Segue: Connect your segue as present modally with your action button.
Programatically: Use self of view controller (UIViewController) and present it modally, like this.
if let tabbar = (storyboard.instantiateViewController(withIdentifier: "tabbar") as? UITabBarController) {
self.present(tabbar, animated: true, completion: nil)
}
Here is result:
Use this, you dont have the Navigation controller over there, thats why it won't push that way, instead, you need to use following code:
self.present(tabbar, animated: true, completion: nil)
You should be aware that Apple's HIG (Human Interface Guidelines) say that if you have a tabbed application that should be the root-level navigation for the entire app. you're not supposed to do what you are trying to do from a human interface perspective.
That said, it should be technically possible.
My guess is that you don't have a navigation controller.
Use the debugger to check the value of self.navigationController, or add a print statement:
let tabbar: UITabBarController? = (storyboard.instantiateViewController(withIdentifier: "tabbar") as? UITabBarController)
print("navigationController = \(navigationController)")
print("tabbar = \(tabbar)")
navigationController?.pushViewController(tabbar, animated: true)
If either navigationController or tabbar displays as nil, that's your problem.
Select the viewController from which the button click triggered and Select Editor form xcode menu->Embed In->NavigationController.
then write this in button action
let tabbar: UITabBarController? = (self.storyboard?.instantiateViewController(withIdentifier: "tabbar") as? UITabBarController)
self.navigationController?.pushViewController(tabbar!, animated: true)
According to your images I think that your tabBarController has no back button. Means user cannot go back.
If that is the case you can do this.
let tabBar = self.storyboard?.instantiateViewController(withIdentifier: "tabBar")
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.window?.rootViewController = tabBar

How to have TabBarController at the bottom itself on selecting menu Item from the side menu?

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)

questions about segue to a viewcontroller

From the iphone system APP “Contacts”, in the “All Contacts” GUI and click “Add”, it will segue to “New Contact” GUI. Then from the “New Contact” GUI and add “new” item then click “Done”, it will seuge to the contact detail GUI(screenshot image 3). The issue is that: I used “Show(push)” to segue to image 3 from “Done” button,
but the NavagationItem in the left corner displayed as “ back to New Contact “ rather than “back to All Contact”.
I attached the screenshot to describe the issue as bleow:
screenshot
I tried two ways:
way 1: pop the vc which matches the image2. The isssue is that New Record page will jump to image1 first, then jump to image3.
if let nav = self.parentViewController as? UINavigationController {
if let vc0 = nav.childViewControllers.last as? AddRecordTableViewController {
nav.popViewControllerAnimated(true)
}
}
performSegueWithIdentifier(Constants.SegueAddRecordVCToViewRecordVC, sender: nil)
way 2:
used the removeFromParentViewController to discard the vc matches image2. The issue is that the Navagation bar button in the left corner still displayed as “
if let nav = self.parentViewController as? UINavigationController {
if let vc0 = nav.childViewControllers.last as? AddRecordTableViewController {
vc0.removeFromParentViewController()
}
}
performSegueWithIdentifier(Constants.SegueAddRecordVCToViewRecordVC, sender: nil)
Why dont you try using self.dismissViewControllerAnimated(true, completion: {}); when "Done" is pressed.

SW Reveal View Controller Right/ Localization

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)

Resources