简体   繁体   中英

UIWebView doesnt load URL , iOS

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?

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

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

}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM