Programatically created TabBarItems and System Images


#1

Hi all

I’m doing a similar thing as described here viewtopic.php?f=54&t=447 specifically I have 3 tabs, and the first tab will have a navigation controller on it… the root view of which is a UITableViewController (I’m doing a master detail thing on the first tab).

My question is around programatically setting the Image on the TabBarItem for that UITableViewController… (see page 108)

Here’s the init() of my UITableViewController.

What I’d like to do is just use one of the system Images like “UITabBarSystemItemRecents” or something rather than using a custom image. Is that even possible? After googling, it seems like people think its not… I see that when programattically creating a TabBarItem I can call

- (id)initWithTabBarSystemItem:(UITabBarSystemItem)systemItem tag:(NSInteger)tag but I’m already in the middle of my UITableViewController’s overridden init !

- (id) init{
	[super initWithStyle:UITableViewStyleGrouped];
	UITabBarItem *tbi = [self tabBarItem];
	[tbi setTitle:@"TheTitle"];
        // This is what I want to avoid
	UIImage *image = [UIImage imageNamed:@"myImage.png"];
	return self;	
}

Also, as a second question… when I push the “detail” view onto the stack of views of the navController that lives on the tab will I need to set the UITabBarItem attributes for that ViewController as well? I’m wondering what is going to live in the init() of the DetailViewController that will have to do with it living on a tab

The functionality im after here is similar to the iPhone “phone” app… if you click on the “favorites” tab and then click the blue circle disclosure button for a “Fave” to see that contact’s details.


#2

I gave up on this, apparently it’s problematic. The best thing to do is use a royalty free appropriate sized image, or just create your own. Check these out, for example app-bits.com/ … a google search will turn up approximately 5000 quadrillion more.


#3
  1. [code]
  • (id)init
    {
    [super initWithStyle:UITableViewStyleGrouped];

    UITabBarItem *tbi = [[UITabBarItem alloc] initWithTabBarSystemItem:… tag:…];
    [self setTabBarItem:tbi];
    [tbi release];

    return self;
    }
    [/code]

  1. No, the tab bar item that is displayed will be the tab bar item of the navigation controller. The topViewController of the nav controller will have no effect on the tab bar, and the tab bar controller won’t even know that the topViewController exists. Thus, both of your problems are solved like so:
UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:...];
UITabBarItem *tbi = [[[UITabBarItem alloc] initWithTabBarSystemItem:... tag:...] autorelease];
[nvc setTabBarItem:tbi];

[/code]