9

I am trying to load a URL when my app starts.

I dragged an UIWebView Object , on my .nib , i created a property outlet , i connected it to the webview and in my view controller i place the following code :

- (void)viewDidLoad
{
    [super viewDidLoad];
    NSString *fullURL = @"http://google.com";
    NSURL *url = [NSURL URLWithString:fullURL];
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
    [webView loadRequest:requestObj];
}

However i just get a black screen on the device , like theres no view at all. Any idea?

donparalias
  • 1,834
  • 16
  • 37
  • 60
  • just recheck that you have done all the necessary things correctly you wont get a black screen if webview is not loaded black screen appears when the ViewController is not properly set via xib – Lochana Ragupathy Mar 25 '13 at 09:18

3 Answers3

24

This is the code I'm using in my application

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    NSURL *websiteUrl = [NSURL URLWithString:@"http://www.google.com"];
    NSURLRequest *urlRequest = [NSURLRequest requestWithURL:websiteUrl];
    [myWebView loadRequest:urlRequest]; 
}
Premsuraj
  • 2,506
  • 1
  • 17
  • 16
1

This is short one

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.

        [myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com"]]];

}
Sukeshj
  • 1,503
  • 1
  • 19
  • 25
  • 3
    Its not actually a short one. You just combined all three lines in to one. Sometimes it reduces the readability. – Ans Jul 13 '15 at 11:44
1

Restart your IOS simulator. It is really not evident, but check, at first, any site in Safari at IOS simulator. After restart of IOS simulator, my webView opened successfully both at simulator and device.

By Amit

Devendra
  • 11
  • 1