2011-03-22 62 views
4

大家好 我有一个基于tabbar的应用程序。在一个视图中,我有一个TTTabStrip与不同的TTTabItems。一切正常(加载普通的UIViewControllers),除了加载UIWebViews。Three20不会在UIWebView中显示网站

在我已成立的URL映射应用程序委托:

TTNavigator* navigator = [TTNavigator navigator]; 
navigator.supportsShakeToReload = YES; 
navigator.persistenceMode = TTNavigatorPersistenceModeAll; 

TTURLMap* map = navigator.URLMap; 
[map from:@"*" toViewController:[TTWebController class]]; // default klasse wenn nichts anderes gewählt ist. 
[map from:@"tt://test" toViewController:[TestController class]]; 

测试控制器包含一个UIWebView中。我可以看到(的NSLog)表示的loadView-方法被调用,但URL没有被打开:

- (void) loadView { 

    CGRect applicationFrame = [UIScreen mainScreen].applicationFrame; 
    self.view = [[[UIView alloc] initWithFrame:applicationFrame] autorelease]; 
    //self.view.backgroundColor = [UIColor blackColor]; 

    NSURL *theURL = [NSURL URLWithString:@"http://www.google.com"]; 
    [webView loadRequest:[NSURLRequest requestWithURL:theURL]]; 

    // support zooming 
    webView.scalesPageToFit = YES; 
} 

举例来说,我可以在一个UIWebView的背景变成黑色。

如何在TTTabStrip下方的web视图中加载谷歌?

非常感谢。

回答

3

尝试以下,并添加方法viewWillAppear中:

- (void)loadView 
{ 
    CGRect applicationFrame = [UIScreen mainScreen].applicationFrame; 
    UIView * newView = [[UIView alloc] initWithFrame:applicationFrame]; 

    // support zooming 
    webView.scalesPageToFit = YES; 

    [newView addSubview:webView]; 

    self.view = newView; 
    [newView release]; 
} 

- (void)viewWillAppear:(BOOL)animated 
{ 
    [super viewWillAppear:animated]; 

    NSURL *theURL = [NSURL URLWithString:@"http://www.google.com"]; 
    [webView loadRequest:[NSURLRequest requestWithURL:theURL]]; 
} 
+0

嗨尼克。非常感谢您的回答。您的loadView方法已被调用,但viewWillAppear方法尚未被触及。这意味着webview仍然是灰色的。 – doonot 2011-03-25 16:28:48

+0

这很奇怪。你可以把一些简单的东西放在TestController的视图中,就像标签一样吗?然后看看它是否显示。 viewWillAppear应该被调用。也许viewDidAppear被调用?你有没有设置webview的框架? – 2011-03-25 16:35:11

+0

你是对的。 viewDidLoad已被调用。我把viewWillAppear的内容放入viewDidLoad中,但没有任何反应。奇怪的是,当我尝试加载一个在IB中创建的简单xib时,它会显示出来。这个webview一定有什么问题。没有webView的框架没有设置.. – doonot 2011-03-25 16:44:50