I work on a Xamarin native app, where I show a modal view containing a list of countries.
I would like to know if there is a way to add a Navigation Bar to this view through the Controller?
Of course, the Navigation Bar will not contain the back arrow button, but a Title and a right button allowing to close this view.
Thanks for your suggestions.
The modal you present needs be wrapped in a UINavigationController rather than only being a UIViewController. This will give you a NavigationBar.
var modalViewControler = new MyModalViewController(); // UIViewController
var navigationController = new UINavigationController(modalViewController);
Related
I have added a bar button item in my app and it is only visible on the storyboard when it is selected , it is not visible at all when I run it on the simulator or real device, any ideas of how I could solve this? thanks !
The problem is that you are already in a UINavigationController interface. Thus, adding your own navigation bar to this view controller won't work; it is hidden behind the navigation controller's navigation bar. What you want to do is modify the navigation controller's navigation bar. You do that by adding a navigation item to this view controller, not a navigation bar.
I can't get the standard back button of iOS into a navigationBar because I can't find it in the Object Library, so can I do it with code or something else?
I just want the normal, standard, blue back button - you know which I mean.
To "automatically" have a back button you need first have a UINavigationController. Then you need to take a different UIViewController and add it as the root view controller in UINavigationController's init method:
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:someOtherViewController];
Be sure to also set a title for someOtherViewController, usually in it's viewDidLoad or initializer. I'll tell you why this is important in a second:
self.title = #"Some other VC";
Then take a second UIViewController and push it onto your navigation controller:
[navigationController pushViewController:anotherViewController animated:YES];
You now have two UIViewControllers on your navigation stack: someOtherViewController and anotherViewController.
Your view will now have a back button with "Some other VC" in it. This is the title of the view controller that was just moved out of view:
http://developer.apple.com/library/ios/#documentation/uikit/reference/UINavigationController_Class/Reference/Reference.html
http://simplecode.me/2011/09/04/an-introduction-to-uinavigationcontroller/
I would also suggest reading up on how UINavigationControllers work and searching this site a bit more for customizing the back button. There are plenty of threads about it.
You can't add the back button yourself. The back button is part of the Navigation controller. If you embed a Navigation controller into your view(s), the back button will appear and be populated by the name of the previous view.
If you're using storyboards select your view controller, then in top menu choose "editor" -> "embed in" -> "navigation controller".
Edit: Here is an exmaple.
I'm running Xcode 7.2. This was driving me crazy, but I figured it out. Here are all the pieces you need to make the Back button appear (make a test project to prove it):
1) You have to have a Navigation Controller and it has to be set to be the initial view controller. So add the Navigation Controller, you will import two tables. Click on the Navigation Controller and on the properties list, check the box that reads "Is Initial View Controller". You will now see and arrow pointing to this view.
2) In our case we want a ViewController and not the included / connected TableViewController, so delete the TableViewController (RootController) and add a new ViewController.
3) Connect the Navigation Controller to the new ViewController by clicking on the top bar of the Navigation controller and orange circle with the arrow pointing left. Hold the Control button on your keyboard down and click and drag from the orange circle to the ViewController and let go. When given the list of options on how to connect the two views, select 'root view controller'.
Done! Now you the functioning navigation bar and you automatically get the back arrow on all segues added. Test this. Add another ViewController and connect to it with a button on the existing ViewController. Use the Control-click-drag approach from the button to the newest ViewController. Select the 'show' option for the new segue you created.
Run it. You'll see the back option has automatically appeared when you click the button and moved to the newest ViewController.
This is all provided by the Navigation Controller, but only when you make another controller the RootController. Happy navigating!
I have made tabbed bar application.Then I put a navigation bar + bar button on one tab view.Then I put a separate view controller on my storyboard.Now i want to open that separate view on click of that bar button.I have tried this by connecting button to view controller with push option.But it does not works.please help?
Then I put a navigation bar + bar button on one tab view.
Seems that you have tried to add UINavigationBar by yourself and as a result (I guess) you have no UINavigationController on tab view. In this case your push segue will not work.
Just place UINavigationController on first tab. Place your bar button on navigationBar that owned by navigationController. The image will help you understand what I've said.
I am working with a universal app and am using storyboards. The basic idea of the app is there is a text view inside of a navigation controller. After the user edits the text view, they have the option to save the data. This text view data is saved in an array. To view the list of saved text views there is a button in the navigation bar, which when pressed segues to a table view. The problem I am having is on the iPad version, this table view appears as a popover and doesn't inherit the navigation bar, which shows the edit button allowing for the cells to be reordered. I am at a loss for finding a solution to show the re-order controls for this table view when in a popover. This works fine of the iPhone version since the table view segue is a push.
Here is the segue code for the popover:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"Show Digital Tape Archive"]) {
if ([segue isKindOfClass:[UIStoryboardPopoverSegue class]]) {
UIStoryboardPopoverSegue *popoverSegue = (UIStoryboardPopoverSegue *)segue;
[self.popoverController dismissPopoverAnimated:YES];
self.popoverController = popoverSegue.popoverController;
} .....
Any help or suggestions appreciated.
After researching and a lot of trial and error, the solution I came up with is creating this popover as a UIViewController instead of a UITableViewController. I then added a toolbar and a tableView. When I originally created this viewController, it was a UITableViewController and I wasn't able to add a toolbar.
There appears to be a way to add a toolbar on a UITableViewController but wasn't able to do it.
I am really new to iPhone development and I need help setting up my views.
I have a view that is named FirstViewController.xib and a controller class for this view.
In my MainWindox.xib I have setup a root controller with a moveToNextView function that is connected to the options bar button item.
So when I click on this item the current view switches to the first view and I am able to swticht back. That works fine so far.
The navigation bar at the top of the screen from the MainWindow.xib is displayed in the first view, too. But when I open FirstViewController.xib there isn't any navigation bar defined (but on build&run it is displayed).
This is a problem for me because I want to add a save bar item to the first view. How do I solve that?
Assuming you have a UIViewController (or UIViewController subclass) that is a child of a UINavigationController. Note, I'm using storyboards so your results may vary when using xibs.
If you do not see a UINavigationBar on the interface, try manually changing the simulated metrics.
Drag a Navigation Item onto the view (anywhere). You should now have a place to enter the title in the interface builder.
Now you can drag Bar Button Items onto the nav bar.
You have to do it from code. Add to your FirstViewController class viewDidLoad method:
UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:#"Save" style:UIBarButtonItemStyleDone target:self action:#selector(doSave:)];
self.navigationItem.rightBarButtonItem = anotherButton;
[anotherButton release];
Just drag a bar button item onto your nav bar in Interface Builder. Xcode automatically wires it up then you can use it like anything else...