Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 782
user1202278 Avatar asked Jul 08 '12 08:07

user1202278


3 Answers

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.

like image 170
Andrea Avatar answered Sep 22 '22 06:09

Andrea


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.

like image 31
Gabriel Avatar answered Sep 20 '22 06:09

Gabriel


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.

like image 22
Olie Avatar answered Sep 24 '22 06:09

Olie