views:

75

answers:

1

I have an app with a UITabBarController that manages some UINavigationControllers, which in turn manage various UIViewControllers.

On 3G phones, the first time I view any particular view via a TabBar button, it's laggy, but thereafter, it's snappy. This isn't noticeable with 3GS phones. My question is how can I force these views to pre-render? I have tried triggering the loadView functions by calling them in a different thread on start-up, but this doesn't do anything I don't think.

For clarity, here is an abbreviated snippet from my code to show what I'm doing. I have five view controllers, but I'm showing just the code for two. The poiVC is just a standard UITableViewController subclass - I don't even have a custom init or loadView function for it.

- (void)applicationDidFinishLaunching:(UIApplication *)application {

  self.mapVC = [[MapViewController alloc] init];
  NavControlBar * mapNavBar = [[[NavControlBar alloc] initWithViewController:mapVC 
                             withControlBar:[mapVC initBar]]autorelease];
  self.poiVC = [[POIViewController alloc] init];
  NavControlBar * poiNavBar = [[[NavControlBar alloc] initWithViewController:poiVC 
                             withControlBar:[poiVC initBar]]autorelease];

  NSArray *tabViewControllerArray = [NSArray arrayWithObjects:mapNavBar, poiNavBar, nil];
  self.tbc.viewControllers = tabViewControllerArray;
  self.tbc.delegate = self;

  [mapVC release];
  [poiVC release];
  [window addSubview:tbc.view];

}

Can I get the poiVC to render while the user is looking at the first screen, so the transition will be fast?

A: 
 [self.mapVC view];
 [self.poiVC view];

You can simply ask for the view of the view controller and not do anything with it. This will return the view, and hence load it for you if needed. The disadvantage is of course that you'll increase your startup time. Also note that your view may be unloaded when memory runs low, which causes lagginess again when switching to those tabs, but (at least tries to) keep your app running (generally considered a good thing).

Johan Kool
I tried the following before: self.mapVC.view; - isn't this the same thing? This doesn't do anything.
Andrew Johnson
Ah... that's probably because you use `-init`, whereas you should use the designated initializer for `UIViewController` (or `MapViewController` if you added one). For `UIViewController ` this is `-(id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)nibBundle`.
Johan Kool
I don't use Interface Builder... and my init function calls [super init]. Isn't this correct?
Andrew Johnson