UITabBarController tagging Tabs?
I hav开发者_如何转开发e 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.
精彩评论