将地址添加到Web视图

时间:2016-10-26 18:35:26

标签: swift webview hyperlink

我尝试以多种方式添加地址,但它并不是一直在运行。有人知道正确的代码吗?

import UIKit

class ViewController: UIViewController {
    @IBOutlet weak var Dziennik: UIWebView!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        webView.loadRequest(NSURLRequest(URL: NSURL(string: "http://www.google.com")!))
    }

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

2 个答案:

答案 0 :(得分:0)

let url = URL (string: "http://google.com")       
let requestObj = URLRequest(URL: url!);
Dziennik.loadRequest(requestObj)

答案 1 :(得分:0)

只需改变一下:

webView.loadRequest(NSURLRequest(URL: NSURL(string: "http://www.google.com")!))

为此:

Dziennik.loadRequest(NSURLRequest(URL: NSURL(string: "http://www.google.com")!))

问题是该物业的名称。