2
我正在關注一個教程,在我的應用程序中顯示來自Web視圖的內容。在swift 2.0中,當我運行模擬器時,模擬器屏幕上沒有響應。Web視圖不能顯示Swift 2.0中的內容
我的代碼:
import UIKit
class ViewController: UIViewController {
@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.stackoverflow.com")
let task = NSURLSession.sharedSession().dataTaskWithURL(url!) {
(data, response, error) in
if error == nil {
var urlContent = NSString(data: data!, encoding: NSUTF8StringEncoding)
print(urlContent)
dispatch_async(dispatch_get_main_queue()) {
self.webView.loadHTMLString(urlContent! as String, baseURL: nil)
}
}
}
task.resume()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
您的代碼爲我工作。你確定你的插座是在你的故事板或xib中正確設置的嗎? – markwatsonatx