I have a rootViewController that is a UITabBarController. A UIToolBar is present in that controller since it has a SearchBar that is global to the app. In certain tabs, there should be specific UIBarButtonItems, or UISegmentedControl, along with the searchBar. In other tabs, there should be nothing in the toolBar, just a title.
What is a good way to lay out the view? Currently based on what tab is selected, the main toolBar from the rootViewController is either used as it is, have a UISegmentedControl added to it, hidden completely and replaced with another viewController that has its own toolbar, etc. To me, I'm thinking that each viewController that is present in its own tab can have its own ToolBar, and reference the global functionality, vs hiding/showing different toolbars.
sorry if this is a convoluted question. Just wondering if people had experience with this. Thanks.
The short answer is that there isn't really a good way to do this. If you're using a tab bar controller, the tab bar will always be visible along the bottom of your screen. Presumably each tab is a UINavigationController with a navigation bar at the top. There's not an appropriate place to put toolbar buttons in this layout.
A better design could be to abandon the UITabBarController and use a UINavigationController as your root view controller. Instead of tabs, you can have a table view with an item for each view of your application. Then you'll have room for a toolbar at the bottom of the screen. In fact, UINavigationController supports having a toolbar at the bottom. You just override the toolbarItems property to return the items that should appear in each of the child view controllers. You'll just need to set toolbarHidden to NO on the UINavigationController, and you're good to go.
Related
I am looking for the best way to implement a UISearchBar on the top of the screen for all the tabs in my TabBarController. I want the SearchBar to be consistent throughout all tabs (i.e. same placeholder text, same search text even after switching tabs).
Is there a way to do this besides passing data to the selected tab each time the user switches tabs? I was thinking of making a singleton UISearchBar and adding it as a subview each time the user changes tabs. I have my doubts about this approach though.
Thanks ahead of time.
You can make one baseviewcontroller. In that you can add your UISearchBar. After that you can inherit your each tab's ViewController from that baseviewcontroller. So, in each tab of your UITabBarController you will get that UISearchBar.
I've been struggling with that too until I tried something and it turned out it's very simple !
All you need to do is to add UISearchBar and a Container View in one UIViewController and then from that Container View set the segue to your UITabBarController and here you go ! One search bar across all the tabs and the solution will also help in separating the logic of the search functionality from the tabs functionality as you will not be forced to implement a search view across all your tabs.
Here I created a view controller with 1 UIView containing a search bar and an account icon and also containing a Container View (The blue part) which will hold out TabBarController
You have to implement search bar in each view controller of tabbar.
Add UISearchbar in all the views.
My first view is a UINavigationController with a rootview, which correctly shows a NavigationBar in IB in the .storyboard. I think this is nice when I am designing in IB, so I know the proportions, since the view is getting a little smaller with a navigationbar. This navigationbar from the navcontroller is pushed on all views in my app, but in IB the bar doesn't show, making it hard to figure out how it's going to look. I have chosen 'inferred' which I thought ment the NavController should automatic implement it, it is ok to just choose 'navigationcontroller' as the top bar in the Simulated Metrics? In some of my viewcontrollers the navigationbar is there, and all settings are 'inferred'.
Thanks.
In each viewController in the StoryBoard file in the Attributes Inspector are several drop down menus.
One of them is "Top Bar".
If this is set to "Inferred" then the navBar will show only if it's parent view shows the navbar (parent as in the view that segues to it).
Somewhere in your hierarchy will be one that has the Top Bar option set to None (or possibly all of them).
Anyway, if you change this it will show the Top Bar in the IB.
HTH.
I want to have a UIView inside of a NavigationController that has 4 buttons. Clicking on any of these 4 buttons will push a UITabBarController that contains a NavigationController with a respective UIView.
Is this possible? Tweetie seems to do something similar.
On my application, I have a tab bar view controller, then inside of that, I have navigation controllers going to individual views in my interface builder. I believe if you just copy this format, it will work.(-> means connected)
Tab Bar View Controller->4 separate Navigation Controller->ui views
I hope this helps
I have created an UITabView application. Each view selected from the bar is a seperate controller with own nib file. I switch between them succesfully.
In the first view I have two buttons (check out the screenshot). When clicking them I want to switch to another views which are the parts of the current view controller. I use:
[self presentModalViewController:anotherViewController animated:NO];
That switches the view, but hides the UITabBar. How to keep the bar on the screen after the switch?
P.S. Sorry for the blurred image. I am not allowed to share to much info.
Well I think you are misusing the modal view controller. For a problem like this I'll say you should put them in a view controller stack using UINavigationController. Instead of making each tab a UIViewController make it a UINavigationController, then you can push and pop view controllers on it, which still show the tab bar.
See http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UINavigationController_Class/Reference/Reference.html
use: tabBarController.selectedViewController = newViewController
edit: UINavigationController is not needed here.
I have a view (and corresponding view controller) in my iPhone app that allows the user to edit settings for the application. This view is accessible via a menu (a table view). I use pushViewController in my UIViewController subclass to get it shown. When I do this, it appears as I expect - the nav bar appears on top of the xib, and the empty space I left up there in the xib is occupied.
I also sometimes show that settings view as a modal view using presentModalViewController. When I do this, the top of the xib starts at the bottom of the nav bar instead of underneath it.
The documentation does say that presentModalViewController will resize the view to fit, so I could see this being expected behavior. However, for me, it isn't desired behavior.
I can kind of work around it by setting the settings view controller to not show the nav bar, but then there's a weird empty space at the top of the view.
Ideally, I'd like to use the same xib in both of these situations. However, maybe that's not a best practice? How do you guys usually reuse a xib?
I was thinking that maybe I could have the view controller shift all of the controllers up if it's in modal mode, but I'd like something better, if it's available.
Each UIView has an autoresizingMask property. By configuring that (can be done in Interface Builder), you should be able to reuse the view and have it automatically resize to take up the whole screen when the nav bar should not be there.
Apple's documentation is here:
http://developer.apple.com/iPhone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/WindowsandViews/WindowsandViews.html#//apple_ref/doc/uid/TP40007072-CH8-SW10