1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

How to use standard OS tabbar items programatically?

Discussion in 'iPhone/iPad Programming' started by jschulbach, Jul 14, 2010.

  1. macrumors newbie

    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?
  2. macrumors newbie

    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!
  3. Moderator


    Staff Member

    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.
  4. macrumors newbie

    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.
  5. Moderator


    Staff Member

    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.

Share This Page