0

I am new to iOS development, i am trying to use a UIWebView using the following code

import UIKit
class SecondViewController: UIViewController {
@IBOutlet var myWebView: UIWebView!
@IBOutlet var webView: UIWebView!
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        let url = NSURL (string: "http://www.chrisharrisracing.com/twitterapp.php");
        let requestObj = NSURLRequest(URL: url!);
        myWebView.loadRequest(requestObj);
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}

However when I build the the web page is not displayed, although when I go to the web address in a browser the page works fine, any help would be appreciated

Nirav D
  • 71,513
  • 12
  • 161
  • 183
Mark Bagnall
  • 1
  • 1
  • 2

3 Answers3

0

I just created a sample project to check your issue and its working for me.

class ViewController: UIViewController {

    @IBOutlet weak var webView: UIWebView!


    override func viewDidLoad() {
        super.viewDidLoad()

        let url = NSURL (string: "http://www.chrisharrisracing.com/twitterapp.php");
        let requestObj = NSURLRequest(URL: url!);
        webView.loadRequest(requestObj);

        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

If you want you can download the sample project from the following link

https://www.dropbox.com/home/SAMPLE%20GIT%20PROJECTS%20%5BSHARED%5D/WEBVIEW?preview=webViewSample.zip

You should add NSTransportSecurity to info.plist

HOPE THIS HELPS.....

Jobins John
  • 1,265
  • 23
  • 45
0

I made a sample project with your code and it works just fine. The only difference is that I didn't use the second outlet (@IBOutlet var webView: UIWebView!) you have in this code. My guess is you haven't added any constraints for your webview and that's why you can't see it. So go to your storyboard choose your webview and then go to the triangle icon at the bottom right and choose Add missing constraints.

Add missing constraints

App running

Of course make sure your internet connection is ok and that you have added the allow arbitrary loads key in your info.plist

0

Maybe you haven't added your constraints yet, which is why myWebView might not be visible. Or maybe, this is probably a longshot, but I've noticed that you have another unused UIWebView called webView. Maybe, just maybe, webView is covering up myWebView, thus you aren't seeing myWebView loading the page.

MShahmeer
  • 159
  • 5