0

Basically when i start my application I show tab view controller, and it shows first tab, and loads only first tab. I would like at the same time to preload rest of the view controllers. I have found this post - Load All TabBar Views

But I am getting error. I call [subcontroller view] in viewDidLoad method of tab bar controller. I am using storyboard. The problem is that I am getting error - Could not load NIB in bundle: 'NSBundle'

What am i missing?

EDIT:

I will try to be more concise - Tabbar has 4 view controllers, corresponding to 4 different tabs. When user presses tab, corresponding view controller is loaded. When you first launch the app, only the first view controller is loaded. Other view controllers are not loaded, they are loaded after user taps their tabs. I want all those controllers to load to memory so i can do something with them (they are not shown on screen).

Community
  • 1
  • 1
MegaManX
  • 8,766
  • 12
  • 51
  • 83

2 Answers2

0

// load all view controller in appdelegate.h file in project

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
 ViewController1 *view1=[[ViewController1 alloc]initWithNibName:nil bundle:nil   ];
 view1.tabBarItem.image = [UIImage imageNamed:@"1.jpg"];
 UINavigationController *navi1=[[UINavigationController alloc]initWithRootViewController:view1];

ViewController2 *view2=[[ViewController2 alloc]initWithNibName:nil bundle:nil   ];
 view1.tabBarItem.image = [UIImage imageNamed:@"1.jpg"];
 UINavigationController *navi2=[[UINavigationController alloc]initWithRootViewController:view2];
  NSArray *navi= [[NSArray alloc]initWithObjects:navi1,navi2,navi3,navi4,nil];

 UITabBarController * bar=[[UITabBarController alloc]init];
 NSArray *navi= [[NSArray alloc]initWithObjects:view1,view2,nil];
 bar.viewControllers=navi;
 [self.bar setViewControllers:navi animated:YES];
 self.window.rootViewController=self.bar;
 [self.window addSubview:bar.view];
  [self.window makeKeyAndVisible];
  return YES;

}

}
NANNAV
  • 4,875
  • 4
  • 32
  • 50
-2

Like what i understand u wanna to load all other view and set it ready to lunch it when u press on tap :) if that what u want u can load it and build it all in background and add it to view but u need to hide it until u press u show the view u want and hide the other views.

this answer work if u build your custom tab :)

Omarj
  • 1,151
  • 2
  • 16
  • 43