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

    #1
    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

    #2
    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

    robbieduncan

    Staff Member

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

    #4
    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

    robbieduncan

    Staff Member

    #5
    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