Webview on ios is blank

0

Hello, I'm starting to program for ios, and I'm not able to run a webview, it always goes blank, see the code:

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

But whenever I run the emulator, the part of the webview goes blank, does anyone know what it can be?

    
asked by anonymous 25.09.2014 / 17:59

2 answers

0

Once you've created the view on your Storyboard and the ViewController files, you link them both to Storyboard , select the Utilities > Identity inspector and tell the ViewController , which in my example I called MinhaWebViewController :

Gobacktotheimplementationfile(.m),andjustbelow@interfacewilldeclaretheoutlet:

@property(nonatomic,weak)IBOutletUIWebView*webView;

Notethatforthemomentthisoutlethasnolinkatall(notethesmallcirclenexttoitwithnofill):

To make this link, go to the Storyboard , with the control key, drag the yellow icon to your UIWebView and select the previously created property:

Nowyoucangobacktotheimplementationfile(.m)andnotethatthesmallcircleisnowfilled:

You can also check out by selecting your UIWebView in the Storyboard and Utilities > Connections inspector . There is a connection entered for this outlet :

Done,justmakeyourimplementationtoloadURL:

NSString*fullURL=@"http://conecode.com";
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[_webView loadRequest:requestObj];

If you still want the entire project, I have it available on Drive for now.

    
27.09.2014 / 12:30
0

For a Swift solution, I recommend using CSafariWebKit

In your file

import CSafariWebKit

And in the ViewController you want to call WebView

let vc = SafariViewController(url: url, barTintColor: nil, tintColor: nil)
vc.presentSafari(fromViewController: self, whenDidFinish: nil)

Use the colors of your app for a better experience.

    
14.05.2018 / 02:30