Segue Not Showing Navigation Bar - ios

I have 2 ViewControllers that are presenting a new ViewController.
The first is in a navigation controller so it works as expected with a segue push.
The second however is from a ViewController without a navigation bar. I'm programmatically presenting this view. However when the destination is presented there are 2 issues...
1) There is no navigation bar.
2) The view shown starts below the first TableViewCell.
func goToLocation() {
let locationTableVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "locationProfile") as! LocationTableViewController
locationTableVC.documentId = selectedDocumentId!
self.present(locationTableVC, animated: true, completion: nil)
}
LocationTableViewController.swift
// MARK: - View Will Appear
override public func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
UIApplication.shared.statusBarStyle = .lightContent
// Make Nav Bar Translucent and Set title font/color
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.isTranslucent = true
self.navigationController?.view.backgroundColor = .clear
self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white, NSAttributedStringKey.font: UIFont.systemFont(ofSize: 20, weight: .semibold)]
self.navigationController?.navigationBar.backIndicatorImage = UIImage(named: "back-arrow-white")
}
Segue shows starting below the first TableViewCell and without a navigation bar.
The first segue which I'm trying to recreate like the second looks like this...

Push your UIViewController with a UINavigationController, like this:
func goToLocation() {
let locationTableVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "locationProfile") as! LocationTableViewController
locationTableVC.documentId = selectedDocumentId!
let navigationController = UINavigationController(rootViewController: locationTableVC)
self.present(navigationController, animated: true, completion: nil)
}

Related

Custom Navigation Bar Subview does not hide when a new viewcontroller is pushed

So on my HomeViewController I added a custom Navigation Bar #IBOutlet weak var navBar: UIView! and I'm adding it to the navigation bar as:
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
self.navigationController?.navigationBar.backgroundColor = .clear
self.navigationController?.view.insertSubview(navBar, belowSubview: navigationController!.view)
self.navigationController?.navigationBar.isTranslucent = false
self.edgesForExtendedLayout = []
Now when I push MenuViewController
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "MenuVC") as! MenuViewController
self.navigationController?.pushViewController(vc, animated: true)
This custom navBar is still on the top. I want the default navigation bar to show again as I only want custom navBar on HomeViewController
You have added that custom navbar into the navigationController.view,
that's why it will be seen on every viewController where navigationController is or will be used.
You can do following to solve this
Add that navbar into subview of current UIView
self.view.addSubview(navbar)
Hide the navigationBar from that particular UIViewController
self.navigationController?.setNavigationBarHidden(true, animated: false)
show it to the next ViewController
self.navigationController?.setNavigationBarHidden(false, animated: false)
Either you should remove the customView from your navigationController before pushing your MenuViewController or access the customview using its tag from MenuViewController's viewWillAppear and remove it from superview or hide it

How can I switch programmatically between view controllers that are not on the same storyboard?

I am trying to switch between a view controller (that is coded programmatically) to a ViewController with the UI Elements on the storyboard.
I am trying to switch between a HomeController to a TabBarController using a button but by pressing the button it switches to a dark screen. I would be glad if some of you could help me out.
Here is my code:
var welcomeLabel: UIButton = {
let label = UIButton()
label.tintColor = .white
label.translatesAutoresizingMaskIntoConstraints = false
label.alpha = 0
label.addTarget(self, action: #selector(handleLogin), for: .touchUpInside)
return label
}()
...............
#objc func handleLogin() {
navigationController?.show(TabBarController(), sender: Any?.self)
}
use this code if you're pushing view from NavigationController
navigationController?.pushViewController("YourViewController", animated: true)
You can do it in following way
let storyboard = UIStoryboard(name: "Your_storyboard", bundle: nil)
let viewController = storyboard.instantiateViewController(withIdentifier: "Your_View_controller") as! Your_View_controller
Now to present
self.present(viewController, animated: true, completion: nil)
Or through navigation controller
navigationController?.pushViewController(viewController, animated: true)
You can try this -
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil) // Give the name .e.g if you have the different story board name
let YourNextViewController = storyBoard.instantiateViewController(withIdentifier: "your story board identifier") as! StoryBoardName/ClassName
self.navigationController?.pushViewController(YourNextViewController, animated: true)
//Or if you want to present viewController
self.present(YourNextViewController, animated:true, completion:nil)

Safe Area bottom layout issue with interactivePopGesture

we have used default tabbarcontroller. Tabbar rootViewController display tabbar and other viewcontroller hidden tabbar.The bottom layout of safearea not update hight when we use interactivePopGesture. All other case its working fine
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if navigationController?.viewControllers[0] == self {
tabBarController?.tabBar.isHidden = false
} else {
tabBarController?.tabBar.isHidden = true
}
}
// issue is in your Tabbar related view controller Properties
Follow Below steps:
1) selected your tabbar prfile viewcontroller
2) disable Hide Bottom bar on Push
3) enable Hide Bottom bar on Push when you push on other view controller
// i was solved this issue like that in appdelegate when iam check user already login then i will remove removeGestureRecognizer from view
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let loginPageView = mainStoryboard.instantiateViewController(withIdentifier: "CustomTabVCID") as! CustomTabVC
let rootViewController = self.window!.rootViewController as! UINavigationController
rootViewController.view.removeGestureRecognizer(rootViewController.interactivePopGestureRecognizer!)
rootViewController.pushViewController(loginPageView, animated: true)
// for bottom bar
// Use this [![enter image description here][1]][1]
// add this line when you navigate to a ViewController hidesBottomBarWhenPushed
let vc = storyboard.instantiateViewController(withIdentifier: VC_IDENTIFIER) as! YourViewController
vc.hidesBottomBarWhenPushed = true
navigationController?.pushViewController(vc, animated: true)
// hope its work for you
or try with Main StoryBoard!
[1]: https://i.stack.imgur.com/IiVrj.png

Swift Modal View Controller with transparent background going beyond tab bar

I tried same code mention in gist : https://gist.github.com/barbietunnie/e5547f35180436ac102cac52a15f8ca3
func showModal() {
let modalViewController = ModalViewController()
modalViewController.modalPresentationStyle = .OverCurrentContext
presentViewController(modalViewController, animated: true, completion: nil)
}
class ModalViewController: UIViewController {
override func viewDidLoad() {
view.backgroundColor = UIColor.clearColor()
view.opaque = false
}
}
Its working fine but in case of tab bar the content is getting beyond tab bar, How can we make content visible upper/front of tab bar?
It worked via vc.modalPresentationStyle = .overFullScreen
I hope it will work for you,
let mainStoryboard = UIStoryboard(name: "Main", bundle: nil)
let controller = mainStoryboard.instantiateViewController(withIdentifier: "ModalViewController") as! ModalViewController
controller.modalPresentationStyle = .overCurrentContext
Thank You.

UINavigationBar set Background, and set translucent not working

I am trying to set the background and trasparecy for UINavigation bar in code, in the ViewWillAppear func. however it doesn't seem to be working.
self.navigationController!.navigationBar.translucent = false
self.navigationController!.navigationBar.backgroundColor = UIColor.blackColor()
the view controller is load via the storyboard id
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier(storyboardId)
vc.title = storyboardId
let navigationController = UINavigationController(rootViewController: vc)
self.presentViewController(navigationController, animated: false, completion: nil)
i have tried setting it there too, doesn't seem to be working.
additionally i tried with UINavigationBar.appearance() to set the properties, this too doesn't work.
You can try with this:
self.navigationController?.barTintColor = UIColor.blackColor()

Resources