I'm using Xcode 4.6.1 to code on Objective-C. I want to know how can I keep the navigation bar shown when I create a modal segue between 2 View controllers, because I'm doing the segue in the storyboard and when I run the application the navigation bar of the second view controller disappears, and I have a done button on that bar but I can't see it.
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- xcode 4 garbage collection removed?
- Unable to process app at this time due to a genera
- Swift - hide pickerView after value selected
- How can I add media attachments to my push notific
swift version:
Follow steps:
Override prepareForSegue()
In order to show a navigation bar on a modal view controller, one way is to insert a navigation controller. You set the segue to this navigation controller as "Present Modally" and can set the presentation to "Full Screen" if needed.
Here's how it might look in Interface Builder, note that the "Title" and "Item" button will show now that we have inserted a navigation controller as the target of our segue.
in storyboard , you should add a Navigation Item to your new viewController, then add Bar Button Item for your done button
In iOS 8 there is a better method. You can use adaptive presentation styles:
Objective-C:
Swift:
Swift 4:
In prepare for segue method set the delegate:
There is an easier way to do this. Like previous comments said (but didn't explain all the steps) you need to embed your desired destination view controller in a navigation controller, then set your destination view controller to be the Navigation Controller, then the Navigation controller calls the destination view controller.
First, embed the VC in a NavVC. Then you must write the code to set the segue destination to be the Nav VC.
The code looks like this:
I hope this makes sense.
You could simply do the following to show the navigation bar:
Objective-C
SWIFT 3
This will show the modal view controller with the navigation bar. Knowledge on Objective-C is limited, so I did not write the part of presenting. You should be able to figure that one out. ;)
Hope this helps!