views:

449

answers:

1

I got a UITabBarController and one of the bar items is a Navigation Controller with some buttons on it. One of the buttons opens up a urlRequest and load it in a UIWebView.

NSURL * url = [NSURL URLWithString:myUrl];
NSURLRequest * urlRequest = [NSURLRequest requestWithURL:url];
UIWebView * web = [tView wView];
[web setScalesPageToFit:YES];
[web loadHTMLString:@"Loading" baseURL:nil];
[web loadRequest:urlRequest];
[self.navigationController pushViewController:tView animated:YES];

For some reason when i click the button for the first time nothing happens.

I used the UIWebViewDelegate protocol to debug it like so:

- (void)webViewDidStartLoad:(UIWebView *)webView
{
    NSLog(@"webViewDidStartLoad");

}

When i click the button nothing happens, and i don't see the NSLog message. When i hit back and click the button again, i see the debug and everything works just find.

Any idea what causing this ?

P.S if i put the : [self.navigationController pushViewController:tView animated:YES];

in the webViewDidStarLoad method the application just hang, since it's not loading it on the first click.

A: 

You need to make sure that tView's view has been loaded. When a viewController is instantiated, its view (and all of it's IBOutlets) are all nil, and remain that way until the view is loaded.

You have two options: move your load stuff into tView's -viewDidLoad method, or force the view to load before calling [tView wView] by, for example, calling [tView view] (this will force the XIB file to be loaded, and all outlets to be connected.

Ben Gottlieb