[英]open links in safari not uiwebview
i try to open links from my local html but i don't know what is wrong in my code. 我尝试从本地html打开链接,但我不知道我的代码出了什么问题。 I added UIWebViewDelegate to the class and the delegate to the View. 我将UIWebViewDelegate添加到类中,并将委托添加到View中。
class TableWebViewController: UIViewController, UIWebViewDelegate {
@IBOutlet weak var infoWebView: UIWebView!
var htmlName:String!
override func viewDidLoad() {
super.viewDidLoad()
self.infoWebView.delegate = self
self.loadHtmltoWebview(htmlName)
self.infoWebView.backgroundColor = UIColor.whiteColor()
self.infoWebView.opaque = false
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func loadHtmltoWebview(name: String) {
let htmlFile = NSBundle.mainBundle().pathForResource(name, ofType: "html")
let url = NSURL(string: htmlFile!)
let request = NSURLRequest(URL: url!)
infoWebView.loadRequest(request)
}
func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
if navigationType == UIWebViewNavigationType.LinkClicked {
//UIApplication.sharedApplication().openURL(request.URL!)
print(request.URL)
return false
}
return true
}
can anybody help me? 有谁能够帮助我? Thanks! 谢谢!
edit: print(request.URL) is shown in the output, so he jumps into the function, but safari don't open 编辑:print(request.URL)显示在输出中,因此他跳入该功能,但野生动物园未打开
Make sure your UIWebViews
delegate property in IB
is connected to your ViewController
. 确保IB
UIWebViews
委托属性已连接到ViewController
。 Otherwise the method you implemented will never be called. 否则,将永远不会调用您实现的方法。 Go to the outlets pane on IB
for the WebView
and connect the delegate outlet with your ViewController
that implements the UIWebViewDelegate
protocol. 转到IB
用于WebView
的插座面板,并将委托插座与实现UIWebViewDelegate
协议的ViewController
连接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.