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

ljg93

macrumors member
Original poster
Mar 13, 2011
98
0
Hey everyone,

I followed this tutorial on how to make a tab bar like the one on instagram (http://idevrecipes.com/2010/12/16/raised-center-tab-bar-button/#comment-985)

I have it functioning inside my app but, I am having trouble getting the tabs to go to certain view controllers and the tab bar to actually work like a tab bar.
Right now, the tab bar just appears on the screen with a black background. (Attached is a screenshot)

if you download the project and go into the baseviewcontroller.m you will see the following code

Code:
-(UIViewController*) viewControllerWithTabTitle:(NSString*) title image:(UIImage*)image
{
  UIViewController* viewController = [[[UIViewController alloc] init] autorelease];
  viewController.tabBarItem = [[[UITabBarItem alloc] initWithTitle:title image:image tag:0] autorelease];
  return viewController;
}
Which I believe sets the tab bar up for the code in the instagramViewController.m
Code:
 self.viewControllers = [NSArray arrayWithObjects:
                            [self viewControllerWithTabTitle:@"Feed" image:[UIImage imageNamed:@"112-group.png"]],
                            [self viewControllerWithTabTitle:@"Popular" image:[UIImage imageNamed:@"29-heart.png"]],
                            [self viewControllerWithTabTitle:@"Share" image:nil],
                            [self viewControllerWithTabTitle:@"News" image:[UIImage imageNamed:@"news.png"]],
                            [self viewControllerWithTabTitle:@"@user" image:[UIImage imageNamed:@"123-id-card.png"]], nil];

I am pretty sure I need to replace it with code like this
Code:
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.
    UIViewController *viewController1, *viewController2;
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        viewController1 = [[[FirstViewController alloc] initWithNibName:@"FirstViewController_iPhone" bundle:nil] autorelease];
        viewController2 = [[[SecondViewController alloc] initWithNibName:@"SecondViewController_iPhone" bundle:nil] autorelease];
    } 
    self.tabBarController = [[[UITabBarController alloc] init] autorelease];
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil];
    self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];
    return YES;

Am I on the right track? Any suggestions?
 

Attachments

  • screen.png
    screen.png
    134 KB · Views: 129
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.