Reputation: 71
I have a button press function that is as follows:
- (IBAction)buttonPressed:(UIButton *)sender {
NSLog(@"Loading WebView controller...");
[self loadUIWebView];
}
The button press function calls the following function, which should load a full screen UIWebView on top of my UIViewContoller (the class where I am calling this is an instance of UIViewController).
- (void)loadUIWebView
{
NSString* currentURL = @"http://www.google.com";
NSLog(@"Attempting to load %@", currentURL);
UIWebView *webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
[webView setBackgroundColor: [UIColor redColor]];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:currentURL]]];
[self.view addSubview:webView];
}
However, no matter what the URL, my app goes to a white screen. As you can see in the loadUIWebView function, I am trying to set the background color of the UIWebView to red in order to see whether it's being displayed - the background is white so I am guessing it's a problem with the way the UIWebView is presented.
Does anyone know what I am doing wrong?
Upvotes: 1
Views: 669
Reputation: 1491
Setting backgroundColor
on a UIWebView
won't show. I'd recommend hiding the web view until it's content is loaded, using whatever placeholder you want, then when the page finishes show the web view. You can see when a web view finishes loading via the -webViewDidFinishLoad:
delegate method.
Upvotes: 1