Reputation: 6657
I am setting up a table, that once a cell is clicked, a dictionary representing the content is passed to the detail view controller. One part of the dictionary is a URL link that my UIWebView is supposed to load.
However, after trying to load the page without success, I tried simplifying the code a little. This simplified code does not work, although all looks well.
webView = WKWebView(frame: self.view.bounds)
view.addSubview(webView)
let URL = NSURL(string: websiteString)
webView.loadRequest(NSURLRequest(URL: URL))
println(webView.loading) //prints 'false'
The page never loads, and even at that println
statement, the webView is not loading. Is this just a bug in Swift right now, or am I doing something wrong?
More info:
If I write the website URL in place of websiteString
, the web view acts normal. However, using an instance variable in its place (that is explicitly typed as a String), the webView does not load the URL. I am not sure what is causing this behavior.
Upvotes: 2
Views: 2300
Reputation: 130193
It's a matter of doing thing out of order. You're instantiating the webView variable else where, and then adding it to the view hierarchy. You then reassign the webView variable to point to an entirely new UIWebView instance, which you tell to load the page. Problem is, this new web view is never added to the view hierarchy. You should receive better results with this:
let webView = UIWebView(frame: self.view.bounds)
view.addSubview(webView)
let URL = NSURL(string: "http://www.google.com")
webView.loadRequest(NSURLRequest(URL: URL))
println(webView.loading)
Upvotes: 2