I added some code to auto display my MenuViewController (SWRevealViewController) but when I do that, my navigation bar of my front view disappear.
There is the code :
if (previousVC == "EditVC")
{
self.revealViewController().revealToggleAnimated(true)
self.revealViewController().setFrontViewController(self, animated: true)
// navigation bar disappear
}
I don't understand why my navigation bar is hidden. Can somebody help me?
It could be that you are setting the front view controller to a view that's not embedded in a Navigation Controller. My suggestion would be to segue normally and then setup your Sidebar menu again in viewDidLoad for the next view controller like so:
// Implement the menu bar functionality
if self.revealViewController() != nil {
menuButton.target = self.revealViewController()
menuButton.action = "revealToggle:"
self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
Also, you want to set the next view's navigation controller not its view controller. Since you're not doing a normal segue, you'll lose the navigation controller.
You just need to add one more Navigation Controller between your sw_front Navigation Controller and View Controller and hide the visibility of navigation bar of first navigation controller.
Related
I am trying to embed my view controller into a navigation view controller so i get the navigation bar and all the other stuff like back buttons. I want to do it programmatically.
It is done like this:
// example ViewController
let myVC = UIViewController()
// create the NavigationController with my VC as root
let navCon = UINavigationController(rootViewController: myVC)
I am trying to create a Tab View Item inside a Tab View Controller which switches to the other Tab View Items not only by tapping on the item in the Tab Bar but also via a button which I create myself.
From one of your VCs the tab bar controller, you can access the tab bar controller by accessing parent. If your VC is also embedded in a navigation controller, you need to access parent.parent.
// assuming "self" is embedded in a navigation controller
if let tabBarController = self.parent?.parent as? UITabBarController {
}
After you have the tab bar controller, you can set its selectedIndex to go to whichever tab you want:
tabBarController.selectedIndex = 1 // second tab
From the docs of selectedIndex:
...Setting this property changes the selected view controller to the one at the designated index in the viewControllers array...
I created a tab bar controller and from one tab item I gave segue to the navigation view controller. And I create a some view controllers attached to navigation controller. So in one view controller I don't need a tabs so in that controller I wrote to hide the tab bar controller that is self.tabBarController?.tabBar.isHidden = true.
When I click the back button of navigation controller from hided tab view controller to previous controller, it doesn't show the tab bar items in previous controllers. But I needed tabs in all view controller except in one view controller. Why does it not show the tabs?
This is my story board :
You can try this in the VC that's before the one you hide the tab in
override func viewWillAppear(_ animated:Bool) {
super.viewWillAppear(animated)
self.tabBarController?.tabBar.isHidden = false
}
You can use hidesBottomBarWhenPushedin the view controller which you don't need tabs. Fits your situation.
let controller = ViewControllerTwo()
controller.hidesBottomBarWhenPushed = true
navigationController?.pushViewController(controller, animated: true)
A little more explanation:
self.tabBarController?.tabBar.isHidden = true globally changed the self.tabBarController's property hideTabBar across its children controllers stack.
In split view controller, I am unable to add images in the navigation bar neither in the title not in the bar button. But, normally if I create view controller and embedded in navigation controller, I can add images to title view as well as bar button.
Issue:
Master view and Detail view. In Detail view I am adding images to title view. It is not working.
Structure
splitViewController --> Navigation Controller --> Detail View Controller
splitViewController --> Navigation Controller --> Master View Controller
Coding
In DetailVC.
func viewDidLoad()
{
super.viewDidLoad()
let image = UIImage(named: "logo")
navigationItem.titleView = UIImageView(image: image)
}
I have the following Storyboard Segue in my Swift project:
The animation is correct, but there is no navigation bar in the destination view controller. I want to force the destination view controller to have a navigation bar. I tried in the destination view controller:
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(true)
navigationController?.navigationBar.hidden = false
}
Or:
override func viewWillAppear(animated: Bool) {
self.navigationController?.setNavigationBarHidden(false, animated: true)
}
But it refuses to show any navigation bar.
How can I perform a vertical segue (like "Cover Vertical") but still display a translucent Navigation bar in the destination view controller?
Edit: My Attributes inspector for the destination view controller:
Try to create the Segue to a Navigation controller instead of your view controller. Navigation bars are only shown for view controllers in a navigation stack. In your case, the source view controller seems to be in a navigation stack but not the presented view controller. Try something like this: