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 do
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:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
UINavigationController *nav = segue.destinationViewController;
AddTriviaVC *triv = [[AddTriviaVC alloc]init];
triv = nav.viewControllers[0];
triv.location = self.location;
}
I hope this makes sense.
That is probably because you don't have a UINavigationController
in your modal. You should use one (or just add a navigation bar to your ViewController in the Storyboard), and present that modally.
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
You could simply do the following to show the navigation bar:
Objective-C
UINavigationController alloc]initWithRootViewController:modalVC];
SWIFT 3
let modelVC = self.storyboard?.instantiateViewController(withIdentifier: "modalVC") as! ModalVC
let navBarOnModal: UINavigationController = UINavigationController(rootViewController: modalVC)
self.present(navBarOnModal, animated: true, completion: nil)
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!
You can add a toolbar programatically by doing the following in -(void)viewDidLoad
NSInteger tbHeight = 50;
tb = [[UIToolbar alloc] initWithFrame:CGRectMake(0, (self.view.frame.size.height - tbHeight), self.view.frame.size.width, tbHeight)];
tb.translucent = YES;
emailButton = [[UIBarButtonItem alloc] initWithTitle:@"Email Results" style:UIBarButtonItemStyleBordered target:tvController action:@selector(actionSheet:)];
UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleBordered target:self action:@selector(doneButtonPressed:)];
NSArray *barButton = [[NSArray alloc] initWithObjects:emailButton,flexibleSpace,doneButton,nil];
[tb setItems:barButton];
[self.view addSubview:tb];
barButton = nil;
You will then have to create an IBAction for pressing the done button and it is done just like this:
-(IBAction)doneButtonPressed:(id)sender {
[self dismissModalViewControllerAnimated:YES];
}
That should give you what you want with your modal view controller.