2011-03-22 61 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