4

Hi all I have a tabbar based application. In one view I have a TTTabStrip with different TTTabItems. Everything works (loading normal UIViewControllers) except loading UIWebViews.

In the app delegate I have set up the url mapping:

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]];

The test controller contains one UIWebView. I can see (NSLog) that the loadView-Method gets called, but the URL is not being opened:

- (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;
}

For instance, I can change the background of the UIWebView to black.

How can I load google in the web view below the TTTabStrip?

Thanks a lot.

Michaël
  • 6,676
  • 3
  • 36
  • 55
nimrod
  • 5,595
  • 29
  • 85
  • 149

1 Answers1

3

Try the following and add the method 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]]; 
}
Nick Weaver
  • 47,228
  • 12
  • 98
  • 108
  • Hi Nick. Thanks a lot for your answer. Your loadView method has been called, but the viewWillAppear method has not been touched. That means that the webview is still grey. – nimrod Mar 25 '11 at 16:28
  • This is strange. Can you put something simple in the view of the TestController, like a label? And then see if it is displayed. viewWillAppear should be called. Maybe viewDidAppear is called? Have you set the frame of the webview? – Nick Weaver Mar 25 '11 at 16:35
  • You were right. viewDidLoad has been called. I put the content of viewWillAppear into viewDidLoad but nothing happens. The strange thing is when I try to load a simple xib that has been created in IB, then it is shown. There must be something wrong with this webview. No the frame of the webView has not been set.. – nimrod Mar 25 '11 at 16:44
  • I finally got it. I have set the frame of the webView and it workes. I have added these two lines into loadView: CGRect webFrame = [[UIScreen mainScreen] applicationFrame]; webView = [[UIWebView alloc] initWithFrame:webFrame]; Thanks so much Nick, you f***ing saved my life :) – nimrod Mar 25 '11 at 16:50
  • You are welcome :) Funny thing is how many times you stumble across those simple problems which consume so much time solving. – Nick Weaver Mar 25 '11 at 21:31
  • Just for completeness, isn't the [newView release] going to create a zombie since it's already autoreleased? – Rayfleck Mar 31 '11 at 19:48
  • You are correct, the autorelease should not be there. I'll correct that. – Nick Weaver Apr 02 '11 at 13:34