我有一个本地HTML文件,我想在ProbabilityPair
中加载,但也想在里面传递一个参数。我可以加载HTML文件
UIWebView
我想将本地传递给HTNL,如webView.loadRequest(NSURLRequest(URL: NSBundle.mainBundle().URLForResource("apprules", withExtension: "html")!))
。有没有办法在Swift中做到这一点?
答案 0 :(得分:7)
let url1 = Bundle.main.url(forResource: "apprules", withExtension: "html")!
let url2 = URL(string: "?lang=ja", relativeTo: url1)!
webView.loadRequest(NSURLRequest(url: url2))
let url1 = NSBundle.mainBundle().URLForResource("apprules", withExtension: "html")!
let url2 = NSURL(string: "?lang=ja", relativeToURL: url1)!
webView.loadRequest(NSURLRequest(URL: url2))
答案 1 :(得分:0)
对于Swift 3,我修改了代码。多谢你们。这篇文章对我有很大帮助。
let url1 = Bundle.main.url(forResource: "apprules", withExtension: "html")!
let url2 = NSURL(string: "?lang=ja", relativeTo: url1)!
webView.loadRequest(NSURLRequest(url: url2 as URL) as URLRequest)
答案 2 :(得分:0)
let url1 = Bundle.main.url(forResource: "apprules", withExtension: "html")!
let url2 = URL(string: "?lang=ja", relativeTo: url1)!
let myRequest = URLRequest(url: url2)
WKWebView.load(myRequest)