View Full Version : How to use standard OS tabbar items programatically?

Jul 14, 2010, 01:17 PM
So I've got a tab Bar with two items I would like to use the contacts icon that you can select if you create the tabbar in IB and drag out a tabbar item. How do I set my programmatically created tab item to use the system icons?

Jul 14, 2010, 01:36 PM
I think I'm a little closer, I've discovered "initWithTabBarSystemItem" where you can specify which system tab bar item you want to use but I can't seem to get it to work. Both of my tab bar items are navigation views but I can't seem to get "recentsNavigationController = [[UINavigationController alloc] initWithTabBarSystemItem: nameHere];" to work. Where would I use "initWithTabBarSystemItem" to set the icon for these two navigation bar controllers that are added as tab bar subviews? Thanks!

Jul 14, 2010, 01:54 PM
UINavigationController *favouritesNavController = [[UINavigationController alloc] init]; // Note this is probably actually a subclass of UINavigationController
favouritesNavController.tabBarItem = [[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:3] autorelease];

The tag is obviously up to you. You can do this within the init of your UINavigationController subclass.

Jul 14, 2010, 02:05 PM
Exactly what I needed. Works great! I'm new to objective C so often the hardest part is knowing the right syntax and it can be hard to do a search when you don't know what method or syntax you need to use.

Jul 14, 2010, 02:08 PM
OK, but going forward you need to pay more attention to the documentation. initWithTabBarSystemItem:tag: is not in the documentation for UINavigationController. It's in the documentation for UITabBarItem. You can't just wish it across to UINavigationController.