Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

jschulbach

macrumors newbie
Original poster
Jun 29, 2010
15
0
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?
 
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!
 
Code:
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.
 
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.
 
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.