男孩,我是一个菜鸟。无法通过按钮在SWIFT中打开第二个URL。应用程序打开,打开时在WebView中加载URL。现在我想要一个按钮在单击时在WebView中打开另一个URL。 (后退按钮,前进按钮并重新加载没有问题)...请帮助,谢谢
导入UIKit
类ViewController:UIViewController {
@IBOutlet var webView: UIWebView!
var URLPath = "http://bandersnatchorlando.com/x19559"
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
loadAddressURL()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func loadAddressURL(){
let requestURL = NSURL(string:URLPath)
let request = NSURLRequest(URL:
requestURL)
webView.loadRequest(request)
}
@IBOutlet weak var reLoad: UIButton!
}
答案 0 :(得分:0)
假设你的故事板中已经有了另一个按钮,并且它被链接到@IBAction,然后在动作中:
let url = NSURL(string:"http://myotherurl.com")
let request = NSURLRequest(URL:url)
webView.loadRequest(request)