Xcode - Change view using Navigation Bar Button Item and Storyboard - ios

I'm making an app with multiple views, using a Navigation Controller. I can easily change views by ctrl-dragging from a button to another view, but it doesn't work by doing the same thing, but with a button in the Navigation Bar.
At first, I had a warning about the style of the button, so I changed it from Plain to Bordered. I have no warning now, but when I click on the button, nothing happens.
Thanks for your help!

Try it again but using a UIBarButton, then link the push action to it and it should work.

Right-click the button and drag the circle next to "Push" under Storyboard Segues over to the view you want the button to navigation to.

Related

Back bar button item with right button

I have implemented a right item button in the navigation bar. I use the storyboard, no code. But now the back button is not displayed. What's the good way to show it again without boilerplate code ?
Thank you!
You can not see the back button on the rootViewController of the NavigationController
NavigationController automatically add the back button once you push some other ViewController to it.
It will display if you have not hides it explicitly.
If you have drag and drop the BarButtonItem as shown in the attached image, Just run the code and back button will automatically get added if it was not your RootViewController.
If it is RootViewController as displayed in images, try to push some ViewController on it, you will get the back button added.
If you add the left bar button item from Interface Builder, you will not get the back button displayed. Then you have to do it manually

xcode/storyboard: can't drag bar button to toolbar at top

I have a view controller that is the detail view of a table. When you click on the row of the table it takes you to the detail view. The detail view is embedded in a navigation controller such that there is a button at the upper left of the navigation bar that sends you back to the table. So far so good.
I now want to add an edit button to the right side of the navigation bar so that you can edit the detail view. My plan is this will add another view controller modally that lets you edit the details of the item. Standard stuff.
However, when I try to drag a bar button item from the list of objects to the navigation bar, it won't take. Instead, when I let go off the mouse button, it leaves the bar button on the tab bar controller at the bottom. (My navigation scheme includes different tabs and for each tab a table, detail view etc.)
Anyone run across this before and can suggest what I'm doing wrong or some sort of workaround to add the bar button item to the right side of the navigation screen. Do I have to add it in code?
Thanks for any suggestions.
I have got the same problem using Xcode6 and I noticed that UINavigationItem is added automatically for the first ViewController that you embed into NavigationController but for the subsequent ViewControllers, you will have to add it manually as follows:
In the Object library, find Navigation Item then drag it to your
2nd ViewController in the storyboard.
In the Object library, find
Bar Button Item then drag it the navigation item that you have created in the previous step.
Now you will have your Bar Buttons stuck to the top of your scene.
Update
The solution still works with XCode 7 but I wanted to add more descriptive photo. Just in case anyone is not really familiar with standard or technical names mentioned above. Notice the red arrows in the right, they refer to step 1, step 2 mentioned above. Also note the hierarchy of views on the left red rectangle.
Nasty trick:
Change your segue to push.
Set the content you need
Set back to show
Then the content will be editable and you have a non deprecated style for segue.
Your storyboard's view controller is likely missing a Navigation Item. You can drag one from the Object library, and drop it on your view controller.
You'll then be able to drag and drop bar button items onto the left or right side of the navigation bar.
i Solved it. drag in 'Navigation Item' to your detail view. than you can drag in the Bar Button Item.
The way that I fixed this issue was, instead of dragging a UINavigationController into the Storyboard and trying to add UIBarButtonItems to that, I dragged in a UITableViewController and then went to
Editor->Embed In->Navigation Controller
Which gave the same result as before except I could add UIBarButtonItems to both sides of the navigation bar with no issues.
Its actually xcode issue.
One trick which worked for me is to add the bar button in the VIEW FILE STRUCTURE ON THE LEFT.Instaed adding on the view directly.
Hope it helps you.:)
I think it is a bug. I had the same problem.I fixed this problem by disable the size classes, then enable it.
You can disable and enable the size classes in Interface builder doc.
I also had this problem, close and reopen the project worked for me.
I believe it's an XCode quirk. I had the same issue. I had to reset Xcode and shift the placement of things on the storyboard to finally get it to go. It's working now.
I think this is a bug of Xcode. In Xcode 8, change the segue in storyboard before the tab bar view controller to all its options (show detail, present...). Then back to show. Try to drag bar button items and modify tile. It works for me!
Did you try "cleaning" your project? I know that helps me sometimes (just go to "Product" > "Clean"). Or, alternatively, delete the navigation bar and try it again.
If you think it's a programming error, feel free to pass on your code. I'd be happy to help in any way I can. :)
You must reset xCode IDE . Close xCode and write the below codes at terminal...It will work.
rm -rf $HOME/Library/Application Support/Developer/Shared/Xcode
rm -rf $HOME/Library/Preferences/com.apple.dt.Xcode.*
rm -rf $HOME/Library/Saved\ Application\ State/com.apple.dt.Xcode.savedState
rm -rf $HOME/Library/Developer/Xcode
Same issue. I had a Table View Controller inside a Navigation Controller and many ViewControllers following further down the chain. A 'Navigation Item' was being created automatically for the FIRST root view controller and I could add a 'Bar Button Item' to this without a problem. Via the Storyboard, drag and drop. But thats all. On the following Table View Controller and further view controllers, even though they were within the initial Navigation Controller (auto generated back button appeared), storyboard would never let me add a Bar Button Item.
Wael Showair's solution did not work for me. Bar Button Items wouldn't appear.
I solved it programmatically in the end (Swift 2.0):
var testButton = UIBarButtonItem(title: "Test Button", style .Plain, target: self, action: "testButtonMethod")
self.tabBarController?.navigationItem.rightBarButtonItem = testButton
No extra Navigation item or Bar Button Item needed.
I was too facing the same problem.I was able to fix this issue by selecting the root view controller option and then in simulated matrix changed the Top bar option to Opaque Navigation Bar and was able to add the item on top of navigation bar.Hope this answer will help someone.
I had the same issue in xcode 8. I had to simply close xcode and reopen the project and then I was able to add the bar button to the Root Controller without any issues.
For XCode 8
There are many answers here. I tried some of them but I couldn't make it.
So I found my solution, just select your ViewController, go Attributes Inspector section and change the Top Bar to Opaque Navigation Bar and Boom. You will see navigation bar on your storyboard. You can change the title or add some item. If you don't want to keep Opaque you can change style to Inferred.
In Xcode 10, I just changed the type of segue going to this new view controller to 'Push (deprecated)', added the navigation item as it was allowed after I made this switch. If you switch back to your originally desired segue type, the navigation item will remain.
Instead of drag the "Bar Button Item" to the "Navigation Controller", drag it to the "Detail View Controller".
As you embed the Detail view into the "Navigation View", "Navigation Item" will be added to the "Detail View Controller". If you drag the "Bar Button Item" to the right side of the Navigation Item, the item will be included under the "Right Bar Button Items"
like Mark Lyons said , I used the same solution.
used push segue first
added the bar item
return back to show segue
done
In Xcode 11, you can drag a button to the navigation bar to create your bar button.

How to manually add a Back button to my NavigationBar?

I would like to know how I can add a back button to my UINavigationBar, I know that If I embed in a Navigation Controller in my main view, that all of this would happen automatically, but that is not what I am trying to do, in fact, the back button could go to any other view I connect the segue to, doesn't even have to be the back.
The back button needs to be the system navigation "back" button, I don't want to have to set image files for my buttons.
I tried dragging in a bar button item in storyboard but nothing shows up, doesn't seem to be doing the trick. The navigation bar was dragged to the view in storyboard (not created programmatically) and it shows up just fine.
I looked at the following similarly asked questions:
-> How do i add a 'back' button to a UINavigationBar manually?
-> How to add a button to UINavigationBar?
-> How to programmatically add a UINavigationBar and a back button on it
but they all point to just embedding the view in a navigation controller, which again, is not what I am trying to do.
If someone can please help me out, provide some sample code I would greatly appreciate it.
Try drag-drop a UIButton object. I have always added manual back button (hardly took the in-built one)

ios storyboard tabbar > ViewController > TableView

I would like to create the following navigation
I have a tab bar program build with storyboard
and I have a View controller with buttons
when I click a button A navigation controller is called
Right now I have made all the connections and everything works fine but..
in order to create the change from the button to the table view I am using modal segue and that removes my tab bar.
I know that push will not work cause its not a navigation but how can I work this out?
I had the same problem but I realized that the best option is do it using a push segue. It's the best option because when you have a table view into a tab bar item it's more usability, it's what customer want. I'm sorry for not solution your problem but I strongly recomend you to use push.

storyboard uinavigationcontroller does not allow me to drag items in

I have an existing ios5/xcode 4.2 app, and I want a button to open a view that will display a list of items, and have a back button and an add new button.
I thought I could achieve this by adding a button to the main view controller, then dragging in to the storyboard a new UITableViewController, then embed a UINavigationController (editor->Embed In->Navigation Controller).
Then i right clicked on the button, dragged it to the navigation controller, and thought, ok this should work.
However, there is no back button, and xcode will not let me drag one in, nor will it allow me to drag in the button bar item "[+]" for the link to add new.
When I run the app, the list shows, of course I have no way to go back to the view controller with the button on it.
What am i doing wrong? - thanks.
(my question is similar to this
but for xcode 4.2)
Embed the main view controller, not the new one, in a UINavigationController. This should add a simulated UINavigationBar to the main view (if not, set one up under Simulated Metrics). At this point you should be able to drop in a UIBarButtonItem to the main view's simulated bar.
Next, draw a connection from your button to the new UITableViewController to set up a push segue. At runtime, the back button will appear in the bar automatically.
Make sure when you try and drag the items into your view controller that the storyboard is zoomed in. XCode won't let you add items if you are zoomed out.

Resources