I have an editor that I am making, and I need a way of editing the document's title. I was considering touching the title of the navigation item and have a custom view appear.
I did this in an initial version of the application with a button bar item (and target/action), but I cannot seem to find a way to do it with the managed navigation bar.
The alternative I was considering was putting another bar at the bottom with an item to do just that, but it doesn't seem like the best design if I don't need to do it, as it takes away from viewing space.
You can set the titleView property of the view controller's navigationItem to a UIButton of type Custom. Then wire the button up to a method on the view controller. Now when the user taps the title, it'll fire the method on your controller.
Related
Ok so I have a tabbar iPhone application. The tabbarcontroller contains about 5 view controllers that are each embedded in their own navigation controller with the exception of 1 in which I just added a navigation bar in IB for a consistent look throughout the app. On every navigation bar in the app, I want a rightBarButtonItem that will open up the same modal view controller no matter where it is selected from. Similar to the "Now Playing" button in the music app, I want the button to stay on every navigation bar regardless of which tab I'm on or how deep I navigate into a navigation controller. How would I go about doing something like this? Is there some way I could simply apply the button to every nav bar in the same way UIAppearance can apply an image to every nav bar in an app? Thanks in advance for any ideas.
A simple approach would be to create a base view controller from which all your other view controllers extend.
With this in place, you could set up a UIBarButtonItem in the viewDidLoad method that attaches itself to the navigation bar and listens for events. From there, it would be quite easy to observe events and present either a modal view controller or push the appropriate view controller on to the navigation stack.
I use this approach for a "logout" bar button item that presents the login view controller when tapped as a quick alternative for users to sign out of their account.
The only down side to this is that each and every view controller that inherits from the base view controller will have the logout button in the navigation bar. Should you need other buttons or want to hide the default button, you need to replace it with another button instead.
It's a quick and easy approach and is also quite simple to remove if required as you can just change the header file to reflect the inheritance rather than sifting through several view controllers removing every instance of the button. It's also easy to maintain as you could overload the button target in any subclasses to perform different functionality when the event is fired.
I have a view controller that's embedded in a navigation controller. Therefore this view controller has a navigation item at the top. One of the things you can do in ios6 storyboards is that you can set the title, prompt and back button for this view controller (because its embedded in a navigation controller).
That being said, when I specify a title and test the app, everything looks good. However, when I place a transparent UIView on top of the navigation item (such as where the title is), the title itself just vanishes. The text itself that I typed into interface builder is gone. I have proven this because if I delete the view I created, the text I initially had is gone.
I tried to mediate the problem by actually setting the title itself outside of the interface builder:
self.navigationItem.title=#"My Title";
But that doens't seem to work either. Does anyone have a clue as to how I can hide/show a transparent UIView on top of a navigationItem in a navigation controller?
EDIT
Any UI element I place in the navigation controller toolbar seems to prevent the underlying title text from showing up. This happens even if the element is marked as transparent AND its set to hidden.
My understanding is that Interface Builder is, more or less, mimicking what you would do if you did the same thing programmatically using the UIBarButtonItem class. The various items in a navigation bar are instances of the UIBarButtonItem class. This class has the following initializers:
– initWithBarButtonSystemItem:target:action:
– initWithCustomView:
– initWithImage:style:target:action:
– initWithTitle:style:target:action:
– initWithImage:landscapeImagePhone:style:target:action:
When you just have a title for the navigation controller, Interface Builder treats it similar to using the initWithTitle: initializer. Basically, this means that, under the hood, a UILabel class is created with the given title and that UILabel is used as the view for the UIBarButtonItem.
When you are dragging the transparent view over the title, however, Interface Builder is instead doing the equivalent of calling initWithCustomView:. This means that the view you are providing is being used as the UIBarButtonItem's view. In other words, when you drag the custom view over the title, you are not placing it on top of the title. You are replacing the title with the transparent view.
One option might be to create a view which has both a UILabel and the transparent view as subviews. Then place that view as the title for the navigation bar. If you give that UILabel the correct font size and shadow, it will look indistinguishable from the system's default title and you will also be able to have the transparent view on top of it.
In IB, you can drag a UIView to the center of the navigation bar, and this will replace the titleView that is there by default (you can do it in code with setTitleView:). If you make its background clear and add a label to it to hold the title, it will look like the default title. You can then add another UIView as the subview of this view, just like you would with any other UIView.
I have a View Controller where I perform a "search as you type". When I press on the SearchBar, hide the Navigation Bar, animated and I also show the scope buttons for my SearchBar. The problem is that when I press on a cell to push a new View Controller the Navigation Bar stays hidden. I KNOW I can set it unhidden, but it will animate from the top. I want to do something similar like in the Email app, when I press on a new cell, a new View Controller is pushed, and the Navigation Bar is animated from the right, like it belongs with the pushed View Controller. How can I make this happen?
Thank you.
Cosmin
Use the UISearchDisplayController to handle the search bar. The behavior you describe is the default behavior.
I have a custom UITabBarController and I want it to slide out the old view and slide in the new view whenever a TabBarItem gets pressed. I looked at UITabBarControllerDelegate but it just offers me to decide if the view gets displayed not how (via shouldSelectViewController).
Is there a way to do that?
(My goal is to have a starfield background that looks almost the same on all the 4 views. It should look like the items get changed and the background just scrolls by a little)
Subclass UITabBarController and make it it's own delegate. Now you can intercept methods like tabBarController:shouldSelectViewController: and manipulate any custom views you have added to the tab bar. And if you add your starfield to the tab bar view, and then use tab controllers that have translucent views the common background can show through.
And you can even intercept tab bar controller methods directly like setSelectedIndex: to have even more control to let you fade things out. But just make sure that you call the super version of the method at some point if you do this so the tab bar remains functional.
I have the search bar in the top of the table and the hidden navigation bar. Along with UISearchBar I use UISearchDisplayController. UISearchDisplayController has the possibility to bring forward the navigation bar. So, when I tap the cancel button in the search bar, the navigation bar fly's down. How can I dismiss this possibility, so the navigation bar will always be hidden?
Thanks
One solution is to make the search bar the table header view in which case it will scroll with the table, and if you don't want it to appear by default then you can programmatically scroll the table down, non-animated, in viewWillAppear it is first displayed. This may or may not make sense for your UI design, but it is, for example, how Safari basically works.
Finnaly!!!! I've found the solution IPHONE: ABPeoplePickerNavigationController hidden navigation bar