UIWebView not loading in Xcode6

(Xcode 6.1, iOS 7.1, iPhone)

UIWebView does not load the page. YES, I connected webView (to the .h file).

Did it 1000 times ... trying not to pull the hair out.

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

Any ideas? I noticed that UIWebViews seem a bit flaky in Xcode 6.

+4
source share
5 answers

I checked your code, but I will try it programmatically,

   - (void)viewDidLoad {    
        [super viewDidLoad];
        UIWebView *webview=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
        NSURLRequest *nsrequest=[NSURLRequest requestWithURL:@"http://www.google.com"];
        [webview loadRequest:nsrequest];
        [self.view addSubview:webview];
    }
+3
source

Assuming that the limitations of the storyboard web view are set correctly, you must in viewDidLoad set yourself as the delegate of the web view

self.webView.delegate = self;

. , - , , , .

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
return YES;
}
+1

Please try below code as its working tone is on my side. Perhaps this solves your problem.

UIWebView *webview=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0,       self.view.frame.size.width, self.view.frame.size.height)];
NSURLRequest *nsrequest1 = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com"]];
[webview loadRequest:nsrequest1];
[self.view addSubview:webview];
+1
source

Part of the code is working fine. I am sure there is no problem there. (WebView also works fine in the iOS8 SDK)
To debug the problem, just implement the webView:didFailLoadWithError:delegate method and see where the error occurred.

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
    NSLog(@"Error loading webview: %@", [error localizedDescription]);
}

We hope this helps you solve your problem.

0
source

Try it,

.h

@property (strong, nonatomic) IBOutlet UIWebView *viewWeb;

.m

NSString *fullURL = @"http://google.co.za";
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
    [_viewWeb loadRequest:requestObj];
0
source

All Articles