Question : Customizing the UITabBarController - or creating a UIViewControlller similar to it

Can I create a UIViewController similar to UITabBarController but does not display the bottom tab bar? I want to replace an existing UITabBarController in an application with this custom UIViewController so the code does not have to change much at all. I am at the moment hiding the UITabBarController by using

- (void) hideTabBar:(UITabBarController *)viewController {    
    if ( [viewController.view.subviews count] < 2 )
      return;
   
    UIView *contentView;
   
    if ( [[viewController.view.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]] )
      contentView = [viewController.view.subviews objectAtIndex:1];
    else
      contentView = [viewController.view.subviews objectAtIndex:0];
   
    contentView.frame = viewController.view.bounds;            
   
    viewController.tabBar.hidden = YES;
}

But the issue is when I go to a system view controller such as ABPeoplePickerNavigationController a black bar appears where the UITabBarController is meant to be.

I want to create a custom UIViewController that acts like a UITabBarController which will be the root view controller and then it displays all the other UIViewControllers in a tab fashion except it doesn't have a tab bar GUI, I will programmatically switch to the correct tab myself.

Answer : Customizing the UITabBarController - or creating a UIViewControlller similar to it

I solved this myself by creating my own container UIViewController to mimic the tab bar

//
//  UITabBarController.h
//

#import <UIKit/UIKit.h>

@interface UITabBarController : UIViewController
{
  NSMutableArray *viewcontrollers;
  int currentViewIndex;
}

@property(nonatomic) int selectedIndex;

- (id)initWithViewControllers:(NSArray *)viewControllers;

@end




//
//  UITabBarController.m
//

#import "UITabBarController.h"

@implementation UITabBarController

- (id)initWithViewControllers:(NSArray *)viewControllers
{
  if (self = [super init])
  {
    viewcontrollers = [[NSMutableArray alloc] init];
    int count = [viewControllers count];
    for(int i=0; i<count; i++)
    {
      UIViewController *vc = [viewControllers objectAtIndex:i];
      [viewcontrollers addObject:vc];
    }
    currentViewIndex = 0;
    [self setSelectedIndex:0];
  }
 
  return self;
}

- (void) setSelectedIndex:(int)index
{
  // removing current view
  UIViewController *viewcontroller = [viewcontrollers objectAtIndex:currentViewIndex];
  [viewcontroller viewWillDisappear:NO];
  [viewcontroller.view removeFromSuperview];
  [viewcontroller viewDidDisappear:NO];
 
  // adding new view
  currentViewIndex = index;
  viewcontroller = [viewcontrollers objectAtIndex:currentViewIndex];
  [viewcontroller viewWillAppear:NO];
  [self.view addSubview:viewcontroller.view];
  [viewcontroller viewDidAppear:NO];
}

- (int) selectedIndex
{
  return currentViewIndex;
}

- (void)dealloc
{
  [viewcontrollers dealloc];
  [super dealloc];
}

@end


Random Solutions  
 
programming4us programming4us