0

I am trying to load a website into a webview which I've been able to do before. But I can't seem to get it to load correctly. I have looked all over Stack and other forums for a solution but I can't seem to figure it out.

My .h file is as follows:

#import "ViewController.h"

@interface ScheduleView : ViewController
@property (strong, nonatomic) IBOutlet UIWebView *webview;

@end

and my .m:

#import "ScheduleView.h"

@interface ScheduleView ()
@end
@implementation ScheduleView

- (void)viewDidLoad {
    [super viewDidLoad];
    NSString *urlstring = @"http://www.google.com";
    NSURL *url = [NSURL URLWithString:urlstring];
    NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
    [_webview loadRequest:urlRequest];

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];

@end

Whenever I try to run my application, it will launch as intended but when I navigate to the ViewController containing the WebView, it will just show a blank screen. And I have tried to use other websites other than google.

This is my first time posting so if I need to give more information, please let me know and I will do my best to reply swiftly.

EDIT:

After putting in the break point on

[super viewDidLoad];

it did come back "nil"

Breakpoint

What does this mean? How do I fix it?

  • Put a breakpoint in `viewDidLoad` and verify that `_webview` is not `nil`. Make sure your outlet is connected. – rmaddy Sep 09 '16 at 16:57
  • 1
    BTW - you have a property, use it. Change `[_webview loadRequest:urlRequest];` to `[self.webview loadRequest:urlRequest];`. – rmaddy Sep 09 '16 at 16:57

2 Answers2

0

Since you are using http://www.google.com You might see below error in your logs

Transport security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.

use solution provided here Transport security has blocked a cleartext HTTP

Community
  • 1
  • 1
Amod Gokhale
  • 2,346
  • 4
  • 17
  • 32
0

add these to your info.plist and try

enter image description here

and make sure, that you have created the connection between your webview and .h file

caldera.sac
  • 4,918
  • 7
  • 37
  • 69