gpt4 book ai didi

ios - 如何编写Web View Controller

转载 作者:行者123 更新时间:2023-11-30 13:14:36 25 4
gpt4 key购买 nike

我想制作一个 webview Controller ,而我正在做的事情,我只是制作一个像这样的 webview Controller 父类(super class):

```

class YQTWebViewController: BaseViewController {
var webview = WKWebView()
var urlString: String?
var activityIndicator: UIActivityIndicatorView!

override func viewDidLoad() {
super.viewDidLoad()
webview.allowsBackForwardNavigationGestures = true
webview.navigationDelegate = self
view.addSubview(webview)
activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: .Gray)
// 30 by 30
let x = UIScreen.mainScreen().bounds.size.width / 2 - 20
let y = UIScreen.mainScreen().bounds.size.width / 2 - 20
activityIndicator.frame = CGRectMake(x, y, 40, 40)
view.addSubview(activityIndicator)

guard urlString != nil else {
return
}
let url = NSURL(string: urlString!)
let request = NSURLRequest(URL: url!)
webview.loadRequest(request)

}

```

我只想创建 YQTWebViewcontroller 的子类,并在完成初始化 View Controller 后覆盖 urlString,但我不知道应该将代码放在哪里。有人能给我一些建议吗?提前致谢。

最佳答案

import WebKit
class YQTWebViewController: UIViewController {
var webview = WKWebView()
var urlString: String?
var activityIndicator: UIActivityIndicatorView!

override func viewDidLoad() {
super.viewDidLoad()
webview.allowsBackForwardNavigationGestures = true
//webview.navigationDelegate = self
view.addSubview(webview)
activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: .Gray)
// 30 by 30
let x = UIScreen.mainScreen().bounds.size.width / 2 - 20
let y = UIScreen.mainScreen().bounds.size.width / 2 - 20
activityIndicator.frame = CGRectMake(x, y, 40, 40)
view.addSubview(activityIndicator)

guard urlString != nil else {
return
}
let url = NSURL(string: urlString!)
let request = NSURLRequest(URL: url!)
webview.loadRequest(request)
}

class SubViewController : YQTWebViewController{


override var urlString: String? {
get {
return self.urlString
}
set {
self.urlString = newValue
}
}
override func viewDidLoad() {
super.viewDidLoad()
urlString = "YOUR URL STRING"
}
}

关于ios - 如何编写Web View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38369845/

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