presentViewController and displaying navigation bar
It is true that if you present a view controller modally on the iPhone, it will always be presented full screen no matter how you present it on the top view controller of a navigation controller or any other way around. But you can always show the navigation bar with the following workaround way:
Rather than presenting that view controller modally present a navigation controller modally with its root view controller set as the view controller you want:
MyViewController *myViewController = [[MyViewController alloc] initWithNibName:nil bundle:nil];
UINavigationController *navigationController =
[[UINavigationController alloc] initWithRootViewController:myViewController];
//now present this navigation controller modally
[self presentViewController:navigationController
animated:YES
completion:^{
}];
You should see a navigation bar when your view is presented modally.
Navigation bar not showing after presentViewController]
You need to present NavigationController as below :
UIViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:ContactUSVCID];
UINavigationController *objNav = [[UINavigationController alloc] initWithRootViewController:vc];
[self presentViewController:objNav animated:YES completion:nil];
Swift: pass navigation bar through presentViewController
To be able to go back, you need to use the existing Navigation controller.
Just add a checking just to make sure.
let newView2 : ViewContrl2 = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("viewContrl2") as! ViewContrl2
if let navCtrl = self.navigationController
{
navCtrl.pushViewController(newView2, animated: true)
}
else
{
let navCtrl = UINavigationController(rootViewController: newView2)
self.presentViewController(navCtrl, animated: true, completion: nil)
}
Navigation Bar not showing when presenting View?
create object of view controller then add navigation controller to it, and then present it :
let VC1 = self.storyboard!.instantiateViewControllerWithIdentifier("MyViewController") as! ViewController
let navController = UINavigationController(rootViewController: VC1) // Creating a navigation controller with VC1 at the root of the navigation stack.
self.presentViewController(navController, animated:true, completion: nil)
How to present view controller modally while keeping navigation bar present. (For a settings view controller)
Create a navigation controller with root view controller as your view controller and then present navigation controller. Something like this.
let vc = // your view controller
let nav = UINavigationController(rootViewController: vc)
self.present(nav, animated: true, completion: nil)
presenting ViewController with NavigationViewController swift
Calling presentViewController
presents the view controller modally, outside the existing navigation stack; it is not contained by your UINavigationController or any other. If you want your new view controller to have a navigation bar, you have two main options:
Option 1. Push the new view controller onto your existing navigation stack, rather than presenting it modally:
let VC1 = self.storyboard!.instantiateViewControllerWithIdentifier("MyViewController") as! ViewController
self.navigationController!.pushViewController(VC1, animated: true)
Option 2. Embed your new view controller into a new navigation controller and present the new navigation controller modally:
let VC1 = self.storyboard!.instantiateViewControllerWithIdentifier("MyViewController") as! ViewController
let navController = UINavigationController(rootViewController: VC1) // Creating a navigation controller with VC1 at the root of the navigation stack.
self.present(navController, animated:true, completion: nil)
Bear in mind that this option won't automatically include a "back" button. You'll have to build in a close mechanism yourself.
Which one is best for you is a human interface design question, but it's normally clear what makes the most sense.
How to present view controller embedded in navigation controller modally?
Refer to this answer here, Option 2: Presenting ViewController with NavigationController
Simply, you need to embed a navigationController into vc3 and then present the navigation controller modally. You will need to create your own back button though.
Swift presentViewController does not have the navigation bar
You can use an Navigation Controller, if you need to handle different ViewControllers.
To add a Navigation Controller, you can simple use the Storyboard Editor.
Select the ViewController - Go to Editor - Embed in - Navigation Controller.
Or:
If you dont need an NavigationController, and just want to have a Navigation Bar, you can use a NavigationBar from the UIItems too. Just select it and drag it in Storyboard Editor to your ViewController. This could be useful when youre second View Controller is a Modal View (and you want to add Buttons to the Navigation Bar)
Swift - Present another view controller with its navigation bar
I fixed the problem using the following code:
let editorViewController = IMGLYMainEditorViewController()
let navEditorViewController: UINavigationController = UINavigationController(rootViewController: editorViewController)
self.presentViewController(navEditorViewController, animated: true, completion: nil)
I just added the navEditorViewController
as it made my navigation bar with its items to appear.
Related Topics
MySQL and Swift - Upload Image and File || Would It Be Better to Use Alamofire
How to Change Height of Uitableviewcell Real-Time
How to Draw a Smooth Circle with Cashapelayer and Uibezierpath
Uiimageview Aspect Fit and Center
How to Get Distance of Object from iPhone Camera Using Image Exif Meta Data
How to Lock Portrait Orientation for Only Main View Using Swift
Wait for Async Task to Finish Completion Block Before Returning in App Delegate
Load Image from Bundle with iOS
Uitableview Add Cell Animation
Linker Error in Xcode 5 for Libzbar.A
Swift 3.0, Alamofire 4.0 Extra Argument 'Method' in Call
Variable Used Before Being Initialized in Function
Alamofire:How to Handle Errors Globally
Change the Font of a Uibarbuttonitem
Launch a Local Notification at a Specific Time in iOS