Connect navigation bar button to view controller in xcode? - xcode

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.

Related

How do I add child view controllers to a tabbed view controller while keeping the tab bar?

I am using Swift 3, Xcode 8.2, developing for iOS 10.
I've got a storyboard that looks like this.
The left view controller is one of three child view controllers part of a tab view controller. The right view controller is a view controller that reveals when "Continue" is clicked.
However, when clicked, the right view controller takes up the whole view and the tab bar at the bottom disappears. There is a "Back" button at the top which is good and I would like to keep that but how do I get the tab bar back?
The problem is not reproducible based on what you've said. On the contrary, when I set up a storyboard Tab Bar Controller -> Nav Controller -> VC1 -> (push) -> VC2, the tab bar is still there when I go to VC2. I can only conclude that there's some misconfiguration in your storyboard that you have not described accurately.

Why is the bar button item only visible when selected and very dull?

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.

How can you keep a new view from covering the tab bar after a segue?

I have a tab bar with 2 tabs. I ctrl-dragged from a button in the first view and released it on the second view and chose "show". The storyboard shows the tab bar on all the scenes, but when I test the button in the simulator, although it does segue to the second view, the second view doesn't show the tab bar.
How can you keep a new view from covering the tab bar after a segue?
Maybe I need to ctrl-drag somewhere else or do this programmatically?
Here is a screenshot of my story board.
When I segue to the "Read Article" view controller I would like to still see the tab bar and star icon at the bottom.
p.s. This may have been answered before with Objective-C, but I am looking for a Swift answer. Thanks.

Standard Back Button in XCode (XIB)

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!

How to add a bar button item in interface builder?

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...

Resources