Webview on Ios goes blank

Asked

Viewed 416 times

0

Hello I’m starting to program for Ios, and I’m not being able to run a webview, 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 every time I run the emulator, the webview part goes blank, someone knows what can be?

  • The code to load Webview is correct. Probably the problem is in the creation of Webview. How are you creating it (nib, storyboard, ...)? Posting the full code would facilitate identification of the problem.

  • I just dragged the webview to the storyboard and declared it on @Property

  • 1

    First check that the property has been declared as Iboutlet: @Property(Weak, nonatomic) Iboutlet Uiwebview *webView. Then check the storyboard connection with the code. Right-click on the view and see if there is an Outlet for this property.

  • Hello, when seeing the outlet, nothing appears, then I click on add, and a view appears, but I did not understand, still remains blank

  • 1

    To clarify what may seem obvious, but only to awaken awareness. You stated the ViewController as your screen controller in the storyboard?

  • I don’t understand , how I see it?

  • Is there any way someone could create an example project with a webview and pass me? I would be very grateful

Show 2 more comments

2 answers

0


After creating the view in his Storyboard and the archives Viewcontroller, you make a bond between these two, there at Storyboard, select the bar Utilities > Identity inspector and inform the Viewcontroller, which in my example I called MinhaWebViewController:

inserir a descrição da imagem aqui

Go back to the implementation file (.m), and just below the @interface declared the outlet:

@property (nonatomic, weak) IBOutlet UIWebView *webView;

Realize that for now this outlet has no link at all (note the small circle next to without filling):

inserir a descrição da imagem aqui

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

inserir a descrição da imagem aqui

Now you can go back in the implementation file (.m) and note that the little circle is now filled:

inserir a descrição da imagem aqui

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

inserir a descrição da imagem aqui

Ready, just do your implementation to load the URL:

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

If you still want the whole project, I made it available on Drive for the time being.

  • everything went well, I didn’t need to download your project. Thank you very much

  • hello man, I ran using Swift, and the emulator works but on my Iphone4 no, on the iphone it goes blank to webview, which may be reminding q I’m ultilizing the xcode6 and Swift. thank you

  • It ran in the same version of iOS that is on iPhone? On iPhone is probably version 7.1, the latest it has, right? You need to look at the versions. If necessary, create a new question by placing your codes for better understanding.

  • I don’t remember the version, but I ran it on the emulator iphone4S, and it ran normally. On iphone goes blank, I created exactly as it is in this video : https://www.youtube.com/watch?v=Rva9ylPHi2w

  • You think Swift doesn’t run on iPhone 4?

  • Surely the Swift is compatible on iPhone 4, It remains to know what is wrong with the implementation. You implemented the methods of delegate of UIWebView, didFailLoadWithError for example? Or the webViewDidFinishLoad to see if it reaches the end?

  • not implemented, when running, it runs the splash pattern with the name of the application, and the webview is blank, what I have to do?

  • I believe it is now more practical for you to create a new question, specifically for Swift, which is a different case from this one. Put your entire implementation in detail so we can understand and help.

Show 3 more comments

0

For a solution on Swift, 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.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.