0

我有一个主 tabController 有两个选项卡,第一个被选为默认选项。按下 tab2 时,文件会加载到 webview 上,但您必须等待几秒钟。在选择 tab2 之前如何加载内容?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.

来自代表,

    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!

第二个视图控制器,

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

2 回答 2

1

尝试

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

[self.window makeKeyAndVisible];

[secondVC view];

强制加载第二个视图。

于 2012-04-16T11:37:45.483 回答
1

如果这个 webview 和 url 请求可以在整个 APP 中不断使用,你可以在全局范围内创建这两个对象,并在第一个 viewController 中初始化它们,甚至在 AppDelegate 中初始化它们。加载第二个视图后,您可以简单地将 IBOutlet webview 指向全局 webview 引用。这可以显着加快第二个视图。

于 2012-04-16T12:04:24.717 回答