user1202278
user1202278

Reputation: 773

Objective C iOS pre load views

I have a tab bar based application with 3 tabs (views). How would I, either in the app delegate or in the first tab that is loaded, would I load the entire contents of the other 2 views in the background?

Right now I have a webView in each of the views in question. Part of my problem is that they are loaded in the viewDidLoad but cause a wait with a blank screen

Thanks

Upvotes: 7

Views: 4678

Answers (3)

Olie
Olie

Reputation: 24675

I typically use something like this:

if (vc.view == nil)      // force load of view
{
    NSLog(@"%s ***** ERROR: view == nil: %@", __PRETTY_FUNCTION__, vc);
}

NOTE: After calling vc.view, the view should never be nil -- that's a pretty serious allocation bug.

Upvotes: 4

Andrea
Andrea

Reputation: 26385

The answer is not that clear to me.. So I you have 3 UIViewController (or subclasses of them) contained in an UITabBarViewController, the way to force them to load their view is call the -view property on each of them in the AppDelegate rich before you add to the UITabbarViewController instance. Something like this:

UIViewController * myViewController = [[UIViewController alloc] initWithNibName:@"mynib" bundle:nil];
[myViewController view];//<--here you are forcing the view to be loaded before it will be called from the tabbatviewcontroller

This is a way to avoid (not at all) the behavior you are experiencing...concepts of loading in background are a lot more complicated.

Upvotes: 9

Gabriel
Gabriel

Reputation: 3359

Try to:

viewController.view.hidden = NO; 

for any viewController you want to pre-load and it has beeb allocated and initialized. That is, after alloc and initWithNibName:... has been done.

Upvotes: 7

Related Questions