Jaume
Jaume

Reputation: 3780

xcode load tabContent before its selection

I have a main tabController that has two tabs, first one is selected as default. When tab2 is pressed, file is loaded on a webview but you must wait few seconds. How could I load content before tab2 will be selected? I tried to call carrega (containing working ViewDidLoad code) function once tabController was set and is executed properly, however when tab2 is selected, content is blank... Thank you.

from delegate,

    viewControllers = [NSArray arrayWithObjects:firstVC, secondVC, nil];
    [tabBarController setViewControllers:viewControllers animated:NO];

    [self.window makeKeyAndVisible];

    [firstVC carrega];
    [secondVC carrega];

//now few seconds later, tab2 will be pressed and should have content already loaded!

second viewController,

-(void)carrega{
//here my loading content code that if is on ViewDidLoad works great but with loading timeout
}

Upvotes: 0

Views: 158

Answers (2)

Wayne Liu
Wayne Liu

Reputation: 1291

If this webview and the url request could be constantly used in the whole APP, you can create these 2 objects at the global scope and init them at the first viewController or even init in AppDelegate. When the 2nd view is loaded, you can simply point the IBOutlet webview to the global webview reference. This could speed up the 2nd view significantly.

Upvotes: 1

kevboh
kevboh

Reputation: 5245

Try

viewControllers = [NSArray arrayWithObjects:firstVC, secondVC, nil];
[tabBarController setViewControllers:viewControllers animated:NO];

[self.window makeKeyAndVisible];

[secondVC view];

To force the second view to load.

Upvotes: 1

Related Questions