gpt4 book ai didi

ios - 按下按钮时在 webview 中打开 url

转载 作者:行者123 更新时间:2023-11-28 12:24:45 26 4
gpt4 key购买 nike

所以我有一个按钮,我试图将其用作用户导航到特定 URL 的一种方式(它确实如此),但是该按钮正在 safari 中打开 url,我希望它显示在我的 WebView 中。

这是我的 view controller.swift 文件:

@IBOutlet weak var webView: UIWebView!
@IBOutlet weak var myProgressView: UIProgressView!
@IBOutlet weak var Home_button: UIButton!


var theBool: Bool = false
@IBOutlet weak var refresh_button: UIButton!
@IBAction func go_home(_ sender: UIButton) {
UIApplication.shared.openURL(NSURL(string:"my url")! as URL)
}
var myTimer = Timer()

override func viewDidLoad() {


super.viewDidLoad()
webView.delegate = self

myTimer = Timer.scheduledTimer(timeInterval: 0.5, target: self, selector: #selector(webViewDidStartLoad(_:)), userInfo: nil, repeats: true)
let websiteurl = URL(string: "another url")
let websiteurlrequest = URLRequest(url: websiteurl!, cachePolicy: NSURLRequest.CachePolicy.reloadIgnoringLocalAndRemoteCacheData,
timeoutInterval: 10.0)

webView.loadRequest(websiteurlrequest)


}
func webViewDidStartLoad(_ webView: UIWebView) {
//if let myProgressView.progress is not nil{
myProgressView?.progress += 0.045
//}

}


func webViewDidFinishLoad(_ webView: UIWebView) {
let loadinglabel = self.view.viewWithTag(100)
loadinglabel?.removeFromSuperview()
myProgressView?.progress = 100
myProgressView?.removeFromSuperview()

}



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

func go() {
myProgressView?.progress += 0.005
}
}

如何在按下按钮时在 Web View 中打开 url,而不是在 safari 中打开?

提前致谢!

最佳答案

试试这个。应该在 Swift 3 中工作

@IBAction func go_home(_ sender: UIButton) {
yourWebView.loadRequest(URLRequest(url: URL(string: "http://www.google.com")!))
}

关于ios - 按下按钮时在 webview 中打开 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43706258/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com