Swift: Force show Navigation Bar in Modal
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:
Swift: Show a navigation bar/top bar on modal view with delegate
Sorry - never mind! I realized that the above code works, and my issue was that I failed to assign the navigationController the class nextScreenNavigationController
in storyboard.
Navigation Bar's content partially not visible in modal on iOS 13
Based on the answer at How to prevent gap between uinavigationbar and view in iOS 13?, which wasn't working for me, I solved my issue using the following code:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if #available(iOS 13.0, *) {
self.navigationController?.setNavigationBarHidden(true, animated: false)
self.navigationController?.setNavigationBarHidden(false, animated: false)
}
}
Or in Objective-C:
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if(@available(iOS 13, *)) {
[self.navigationController setNavigationBarHidden:true animated:false];
[self.navigationController setNavigationBarHidden:false animated:false];
}
}
How to hide a navigation bar from first ViewController in Swift?
If you know that all other views should have the bar visible, you could use viewWillDisappear
to set it to visible again.
In Swift:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.setNavigationBarHidden(true, animated: animated)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
navigationController?.setNavigationBarHidden(false, animated: animated)
}
iOS Opening a stand alone navigation controller as modal
There is only one problem with your code. You set the controller property to show it on full screen but you are presenting the navigation controller. You need to the set the property of the navigation controller as the full screen.
let storyboard = UIStoryboard(name: "Main", bundle: nil)
if let vc = storyboard.instantiateViewController(withIdentifier: "idDetailsVC") as? DetailsVC{
let navigationVc = UINavigationController(rootViewController: vc)
navigationVc.modalPresentationStyle = .fullScreen
self.present(navigationVc, animated: false, completion: nil)
}
You can add a custom button in the navigation controller now. But remember you can't pop as the DetailsVC is the rootViewController of the navigation Controller's stack. Since it was presented, you can dissolve the navigation controller, and the presenting view controller will show. However you have to use a custom action.
Also it's not a good idea to force cast.
To create your back button, create a UIBarButtonItem and add to the left bar item like this.
func setupNavigationBar(){
let backButton = UIBarButtonItem(title: "Back", style: .done, target: self, action: #selector(backButtonPressed))
self.navigationItem.leftBarButtonItem = backButton
}
@objc func backButtonPressed(){
self.navigationController?.dismiss(.default)
}
The backButton is custom created with title. You can initialize barbuttonitem with image as well. I am not sure if the system has one itself or not. So I hope you get the gist of it.
Swift - UITableViewController with navigation bar
Click the ordersViewController
. Then in the top bar Editor > Embed In > Navigation Controller and remove the navigationbar
you currently have in the VC.
Additional navigation bar slides from top on modal segue push
I found the bug!
The login view controller had the method:
override func viewWillDisappear(_ animated: Bool) {
navigationController?.setNavigationBarHidden(false, animated: animated)
super.viewWillDisappear(animated)
}
It was necessary to recover navigation bar in the after-login view controller but was making the annoying effect in registration view controller. So I deleted it, and instead, I inserted the snippet to after-login view-controller:
override func viewWillAppear(_ animated: Bool) {
navigationController?.setNavigationBarHidden(false, animated: animated)
super.viewWillAppear(animated)
}
Related Topics
Storyboard Entry Point Missing
How to Position Child Skspritenodes Inside Their Parents
Ios9: Using Dynamic Framework with Simulator and Device
How to Rearrange Views in Swiftui Zstack by Dragging
How to Convert Nsset to [String] Array
Can't Able to Get Video Tracks from Avurlasset for Hls Videos(.M3U8 Format) for Avplayer
Cannot Assign to Property: 'Xxxx' Is a Get-Only Property
Swift: Force Show Navigation Bar in Modal
How to Fix ' *Pod* Does Not Support Provisioning Profiles' in Azure Devops Build Agent
Confusion Regarding Overriding Class Properties in Swift
Change Default Global Tint Color in Swift
Delegate Using Container View in Swift
How to Initialise Cvpixelbufferref in Swift
How to Create a Hud on Top of My Scenekit.Scene
How to Retrieve the Type of an Object in Swift