UITabBarController tagging Tabs? - iphone

I have an app that uses various view controllers as tabs. I'm in the process of saving the custom tab order when the app shuts down. I'm trying to find a generic identifier for my various view controllers without having to add an attribute to each controller (which my backup plan).
I would think, similar to UILabels, that maybe view controllers would support tagging or something similar? I'm having trouble finding in documentation so is there a way to tag or otherwise uniquely identify each view controllers in my UITabBarController?

How has nobody suggested the correct answer so far? When creating your tab bar items, use the tag property of the tab. It's easily accessible in Interface Builder as well.
- (id)initWithTitle:(NSString *)title image:(UIImage *)image
tag:(NSInteger)tag Parameters
title
The item's title. If nil, a title is not displayed.
image
The item's image. If nil, an image is not displayed.
The images displayed on the tab bar are derived from this image. If this image is too large to fit on the tab bar, it is scaled to fit. The size of an tab bar image is typically 30 x 30 points. The alpha values in the source image are used to create the unselected and selected images—opaque values are ignored.
tag
The receiver's tag, an integer that you can use to identify bar item objects in your application.

I'm pretty sure you'll have to just go with your backup plan. There are advantages to that, anyway, because it gives you more control over the whole process and how you'd like to save and differentiate between your tabs.
It shouldn't be much work to quickly subclass UITabBarController and add a string/int to identify the items.

Related

Set array of TabBar items dynamically with scroll view

How can I add a TabBar on top of the iPhone? Also I need to set an array of TabBar items dynamically with scroll view.
For more details refer to this url
I need to create tabs like Top News, City, India, World, etc.
UITabBar generally is placed at the bottom of the screen and there usually only one per app. It may be possible to sidestep this, though Apple probably won't like it.
You do not directly manipulate a UITabBar. Instead, you add navigationControllers to the UITabBarController. Tabs can then be manipulated by setting the tabBarItem property on the NavigationController.
All that said having reviewed the screenshot, I am almost certain that a UITabBar is the wrong choice for this. You'd be better off rolling your own control or perhaps using UISegmentedControl.

Replacing UINavigationControllers NavigationBar with UIView

I am developing app that has multiple skins and I have a dilemma on how to implement this.
One of the solutions would be to have separate nib files for every skin, and load it depending on which skin is currently selected. Problem with this is that I can't edit navigation bar of navigation controller (which my app uses), and I have to change it's background image and back button image etc.. I came up with an idea to hide this navigation bar on every screen and replace it with custom UIView in Interface Builder which will act as navigation bar and custom back button with IBAction for popping current View Controller, so that user won't see any difference.
Is this approach acceptable and if I make it this way, will I have problems with rejection in App Store?
If you choose to hide & replace the UINavigationBar with your own UIView it's no problem as far as Apple goes.
However, I can tell you that you will have to spend some time trying to replicate some visual effects that come naturally with UINavigationBar.
For example, when you push/pop a new controller, you will see that the navigation bar title will slide & fade beautifully. The same applies for left and right bar items.
Personally I would not completely hide the UINavigationBar, but customize it. In the end it all depends on what you want, but by default the UINavigationBar is pretty customizable.
You can add your own buttons or even entire UIViews as left and right bar items. Also, you can add your own UIView as the title (with your own label, custom font or whatever) or change the background.
EDIT:
To easily customize the looks in your entire application, you can subclass UINavigationController and create your own CustomUINavigationController. Then, in viewDidLoad method you can change whatever you want to the navigation bar and this will be accessible in the entire application.
No way, what you are doing is perfect. This will work & no way it will get rejected from app store (just based on this approach). I too have explored several ways to provide skins & what you wrote seemed to be the least hassle-some. Plus its way more easier to create UI elements in Interface Builder hence the separate nib files for different skins.
I am saying this so confidently 'coz I have done the same thing & app store approved.
Best of luck.

How to make a horizontal scrollable UITabBar in iOS?

The UITabBar in my app consists of 10+ items, but the width is enough to put all 10+ items.
How to make a horizontal scrollable UITabBar in iOS ?
Thanks.
You'll have to roll your own to at least some extent.
What might work, would be to create a UITabBar view (not the controller) and embedded it in a UIScrollView. You could then use that in place of your regular Tab Bar control by adding it to your TabBarController.view/tabBarView or something. Of course you'd have to play around to get it to look right, and I'm not sure if just setting the view to something wider will actually make it display more items or not.
Of course, for best results you'd probably want to do something entirely custom.
From Apple's Developer Portal:
If you add more than five items to the viewControllers property, the tab bar controller automatically inserts a special view controller (called the More view controller) to handle the display of the additional items.
Source
Seems like you will need to make a custom tab bar.
They also said this in the next paragraph:
Although the tab bar view is a key part of your tab bar interface, you do not modify that view directly.
You might be breaking Apple's design guidelines by doing this.
You can certainly go and create a custom class of the UITabBar (embedding it into a scrollview etc.)..but why re-invent the wheel? After searching around I found several third-party classes already created that work well and are easy to use and highly customizable..In order of personal preference:
M13InfiniteTabBar -
https://github.com/Marxon13/M13InfiniteTabBar
JSScrollableTabBar -
https://github.com/jasarien/JSScrollableTabBar
InfiniTabBar -
https://github.com/iosdeveloper/InfiniTabBar

Multiple UINavigationControllers similar to Maps

I'm looking to create a UI similar to that of the Maps application just to try out some odds and ends and brush up on my knowledge of interface builder.
What i'm struggling to discern at the moment is how the Maps application handles the interactions between the toolbar and the navigation controller and which UI elements are needed to mimic the interface. I'm guessing that the Maps app only has one view controller which kind of negates the need for a navigation controller so i'm not sure if i'm using the right application template currently but i'll come back to that one later.
To give you an idea of what I'm looking to copy, if you search for directions between two locations and then hit route, the navigation controller changes from:
[Clear] Directions [Cancel]
to:
[Edit] {car | train | walk} [Start]
That's all fine so far, nothing out of the ordinary from what i'm used to doing. What is confusing me however is the semi transparent view underneath the navigation controller that displays the total distance and time (or other information depending on the search method). What is the UI element? Is it simply a toolbar tacked on to the main view? How would I go about adding this to my app, is it part of the view, or part of the navigation controller?
Also, in a similar vein... Clicking the "Search" segment in the toolbar displays the search field at the top of the app. Is this in the navigation controller, or is the navigation controller hidden whilst the search field is displayed? Again, clicking "Directions" displays the search field but this time with an additional search field and a button to switch the order of the fields. How is this achieved?
I'm not so good with the terminology so excuse me if i've mixed up some terms. I'm just trying to get to grips with the UI elements as i've spent most of my time learning OpenGL so it's all a bit new to me still. If anyone can point out the right UI elements used in the Maps application, that would be greatly appreciated!
Many thanks for reading.
Edit: I've uploaded an image to illustrate the UI elements i'm querying in this question.
I have no inside information, so I'm speculating on how I'd do it.
I'd use a UIToolBar for both the top and bottom bars, not a navigation bar. You can put a tool bar anywhere as they're just a subclass of UIView.
The semi transparent view underneath the navigation controller is likely just a custom view on top of the map view. Again, just a subclass of UIView.
The items in both toolbars would call methods in the view controller that could change the contents of either tool bar or hide or show other views.
For example, the Search button might call a showSearchToolbar: method, while the Directions calls a showDirectionsToolBar: method. Both methods would just change the contents of the top tool bar and hide or show the view beneath the top tool bar.
Check out the UICatalog example code from Apple to see how to dynamically change the contents of the tool bar.

Best way to handle segmented bar and multiple views?

I have a User Filter section of my iPad app. There is a segmented bar with 5 buttons for 5 types of filters.
Clicking each of the buttons will load up the respective view..
My question is.. would the best way to handle the UI of each filter to have several views in this nib and load/unload accordingly.. or would best practice be to create the information in a scrollable view?
below is the setup..
http://imgur.com/iuufU.png
Thanks in advance...
Generally, go with separate views. The Scrollable view is an approximation of what you're trying to achieve (by the looks of things), whereas the separate-views more closely reflect your aims.
Some typical dvantages:
if you change your UI design, e.g. if one of those filters has to go in a different page, but 4 stay here ... then it's easy to move the whole View without changing the eixsting ones.
you can put each view in a separate NIB file (if they're different), or loaded from a separate ViewController instance (if they're the same), and you get some of the advantages of Apple's automatica memory management of VC's / NIBs.
Usually, people start with the same view for each filter, using a single VC class (instantiated multiple times, once per tab).
Then, as the app evolves, they find that one tab needs a different layout, so they add another VC class, and only need to update the alloc/init line for that one tab.