What I mean is a static "top-bar" that I can edit from the relevant swift file.
I don't actually want any of the navigation function, but I want to be able to change what it says situationally.
I've looked around quite a bit but can't seem to find a solution for this seemingly simple task.
Thanks in advance.
I am not quite sure, if this is what you want.
However, if you want a navigation bar with customizable navigation item title/text, then you can just add Navigation Item from the Object library to your Navigation bar.
Then in the inspector, you can select custom and specify the title of that navigation item as you desire. You can also create an IBOutlet for it and change the title in your code in different situations.
Ctrl Drag the bar button from the storyboard to the appropriate view controller implementation file. I.e viewController.h. This will create an IBAction, which you can name.
- (IBAction)nameOfAction:(id)sender {
// Action goes here
}
Any logic applied inside will be called on button press.
So it was a pretty easy, but not straightforward solution...
All I had to do was
Add a navigation bar, by clicking Editor -> Embed in -> Navigation Controller
The hard to find part, use the property self.navigationItem.title = "title" to change the title.
The second part I found from hgwhittle's answer in this question, which also covers how to change the nav bar title, the tab bar title, or both.
UIViewController Title attribute in Storyboard
Related
I'm in XCode 7.2.1 and I am trying to make a view that is reusable and should have some custom elements in the navigation bar.
If I would add a view to my storyboard, connect it via a segue to the navigation controller and make sure there is a "Navigation Item" in the view, I could see the navigation bar and edit my items in it.
If I manually add a Navigation Item to a XIB however I can't see anything. Even if I switch in the simulated metrics settings Top Bar to something else than Inferred or None.
I don't want to use the storyboard, if possible. Is there a descent way to make the navigation item visible and edit it?
Thanks in advance.
I don't think you link your View Controller correctly with Navigation Controller. When you link it, you should choose with root View Controller. If you link it correctly, you don't have to add NavigationItem manually.
By the way, you shouldn't do the customization for Navigation bar directly in xib. All you can do is only to set the Title, Prompt and Back Button text.
Do it in code! I think you won't have different styles for navigation bar in different views, right? That would be too silly.
I'm developing a (so far) simple iOS application using storyboards.
At one place in the storyboard, I have:
Navigation controller -> Table View (prototype content) -> Regular view
The "regular view" is accessed from a + (PLUS) button in the navigationbar in the table view. In the "regular view" I would like to have a save button in the NAVIGATION BAR. However, when I drag it from the object library to the "regular view" it appears in the TOOLBAR (at the bottom of the screen) instead of in the NAVIGATION BAR. I have not found a way to move it, or found any settings where I can change it. I'm not sure if there is something constraining me from putting a button there or if XCode just mess with me. (I'm new to iOS programming)
Notes:
In the "regular view", I have a back button and a title. According to the design guides I should be able to have one more button.
Thanks for any help!
If anyone faces this problem, I did the following:
I couldn't add a Bar button because there were no top bar in that view. First I tried to put a Navigation Bar in the view, but Xcode crashed. Then I tried to put a Navigation Item, which worked. After that I could place my bar button in the top bar.
What I don't understand is why I could put the Add (+) button in the previous view, since that doesn't have any navigation entry either, but I'm guessing it's since that view was the root view controller of a Navigation Controller. Someone else can maybe give a more detailed answer.
There isn't any solution for this so far. There are however some workarounds for this problem.
Check this pretty cool answer by #Shimanski:
https://stackoverflow.com/a/20419513/2082569
& also this by #ecotax:
https://stackoverflow.com/a/17019667/2082569
I can't solve this despite my best efforts. I also consulted the Apple documentation and several related questions here and still I have a mental block on this.
Using Xcode 6, I embedded a table view controller in a navigation controller and could set the title of the navigation bar in the table view controller, but not in the two view controllers that are connected to the table view via segues.
I did think there was a navigation bar on these two view controllers because after I embedded the table view controller in the navigation controller, it blocked out my topmost textfield in both. I repositioned that so that isn't a problem, but in storyboard I still don't seem to be able to click inside the navigation bar to add a title and now having added a navigation bar manually to test it out, I can see that there is only one navigation bar in document outline.
So do you simply have to set the title of the navigation bar programmatically or with an IBOutlet or some such? Doesn't seem like you can click into it in story board.
I am pretty sure this is a bug in Xcode... I have experienced the same issue and most of the time it was solved by restarting Xcode.
** In addition you may be able to get it solved by doing:
Drag a Navigation item from the objects pane into the viewcontroller or tableviewcontroller. This seemed to work for me. I did notice that the navigation area was missing from the "Document Outline Pane".
I hope this helps.
I had the same problem while following apple's swift guid. Dubble-clicking the "navigation bar" did nothing for me.
How I solved it:
1: Select the "navigation item" from the document outline pane.
2: Open the attributes-inspector.
3: Select the title field and write the title here instead.
I had the same problem. What worked for me was to select the controller that I couldn't set the title on, click editor -> embed in -> Navigation controller.
Then you should be able to edit the title and when finished, delete the navigation controller and reconnect the two original controllers.
The screen that was previously embedded should now contain the title you created earlier.
Try to set title programmatically -> self.navigationItem.title = #"REGISTER";
place this is your prepare for segue:
[segue.destinationViewController setTitle:#"New Task"];
Connect your Navigation Item to your class (i.e. UIViewController), and access it's title programmatically by writing the following within your viewDidLoad:
navigationItem.title = "whateverTextHere"
You can also set the view controller's "title" property instead, which will automatically set the title of a navigation item or tab bar item.
By selecting the view controller in the storyboard, you can set the title under "View Controller" in the Attributes inspector (Xcode 9):
Be sure to use a Relationship Segue, not a Manual Segue when embedding controllers.
Update to this issue if someone else need it:
Make a segue between ViewControllers
Pick Kind option as Show(e. Push)
Than change this Kind option on some deprecated - ex. Push
Now you can edit your tittle and navigation items from storyboard
Remember to change Kind option again on what you need.
None of the answers worked for me.
This worked:
Delete nav connection
Ctrl drag a new nav connection
Make it a show connection
Now you can edit the title
Delete the nav connection again
Create the original nav connection type again
It seems that this is indeed a bug in IB 🙁
I'm newbie with Xcode, I'm learning it and trying to make my app.
Now I would like to put Navigation Bar func at the bottom of the screen with some customize.
I turn on "Shows Toolbar" at Navigation Controller and put my button there, but I cannot customize it.
Everything that I found about customizing Navigation Bar at the top of the screen or about customizing TabBar when people are talking about bottom of the screen.
Please, can you give me a code examples to build something like this at the bottom of the screen:
https://dl.dropboxusercontent.com/u/1338320/nav.png
Thanks in advance!
I'm not sure what you are trying to customize (button or bar) but when there is a bar at the bottom of the screen that is not a tab bar it is a tool bar not a navigation bar. The two are related but they each have their own class. Tool bars use UIToolBar not UINavigationBar. The tool bar is independent of the navigation controller and the two work together well. For any views that don't want a tool bar just set it to hidden in -viewDidAppear: (you will need to un hide it in views that use it).
dimimpou is right. You can accomplish this by using a UITabBarViewController and one UIBarButtonItem for "ADD ONE" and "MY STATS".
If you get lost in references(I sometimes get lost too), I may provide a simple example.
Note that if the interface provided by UIKit doesn't meet your need you can:
Use category over UITabBar or UITabBarItem.
If 1. doesn't work sadly you'll have create your own view controller which is simulate UITabBarViewController(requires some time, but it's worth)
Edit:
You can use a UINavigationController inside a UITabBarViewController.
You can easily do this. The way I understand it, you want this "Toolbar" to show from a button in the navigation bar. Just put a tab bar with what you need and make it show when the user presses the button on the navigation bar. on this buttons action put this code: self.tabBar.hidden = NO; and on the storyboard uncheck the bar visibility option. Hope it helps!
I'm new to this :-(.
I have a pretty standard Tab Bar Controller to which I've added a UIButtonBarItem (I used the storyboard editor to do this). It all looks fine, but I don't know how to handle the "button press" event. I have established a delegate for the tab bar controller, so I can capture the "didSelectViewController" events (not that it seems to help :-).
I think I'm missing something obvious.
The Tab Bar Controller automatically creates buttons when you connect other views to that one. I had this same problem using storyboard editor even though you can put it in there I believe it won't allow you to use it. I think even just setting up an IBOutlet won't work.
In the docs:
http://developer.apple.com/library/ios/#documentation/WindowsViews/Conceptual/ViewControllerCatalog/Chapters/TabBarControllers.html
Apple specifically talks about how you just create the views and the buttons are automatically handled for you.
Otherwise if you want a tab button that doesn't bring up a new view (thats what I wanted), supposedly that doesn't fit in with Apple's design principles for what a Tab controller is.
I finally stumbled across the solution:
Set up a delegate for the TabBarController ()
Create a method on the delegate to handle the action: -(IBAction) someHandler:(id) sender;
Drag a Bar Button Item into the "Navigation Bar" of the common Tab Bar Controller
Select the bar button, control-drag to the "First Responder" and select the "someHandler" method.
That's it, not that hard, should have figured it out earlier.