[英]How add WKWebView on TableView programmatically
I'm trying to make a simple application mapping data from the network to the table. 我正在尝试制作一个简单的应用程序,将数据从网络映射到表。 But the site requires the authorization of OAuth 2.0 and the receipt of the token.
但是该站点需要OAuth 2.0的授权和令牌的接收。 Wanted to programmatically show a view with a WKWebView for this.
想要以编程方式显示带有WKWebView的视图。 I do this:
我这样做:
import UIKit
import WebKit
class TableViewController: UITableViewController, WKUIDelegate {
var webView: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
let webConfiguration = WKWebViewConfiguration()
webView = WKWebView(frame: CGRect(x: 0.0, y: 0.0, width: tableView.bounds.width, height: tableView.bounds.height), configuration: webConfiguration)
webView.uiDelegate = self
tableView.addSubview(webView)
let myRequest = URLRequest(url: URL(string: "https://www.google.ru/")!)
webView.load(myRequest)
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 5
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "idFriendCell", for: indexPath)
cell.textLabel?.text = String(indexPath.row)
return cell
}
}
but, seperators TableView are overlapping my WebView: 但是,分隔符TableView与我的WebView重叠:
How to do it right?
怎么做对?
At least you have 2 simple solution here. 至少您在这里有2个简单的解决方案。
1) You can create custom UIViewController
, replacing your TableViewController
. 1)您可以创建自定义
UIViewController
,以替换TableViewController
。 That inherit UIViewController
not UITableViewController
. 继承
UIViewController
而不是UITableViewController
。 Add manually tableView
there, conform controller
to UITableViewDataSource
and UITableViewDelegate
if needed. 在那里手动添加
tableView
,如果需要,使controller
符合UITableViewDataSource
和UITableViewDelegate
。 Then add webView
to its view
. 然后将
webView
添加到其view
。
2) You can create new controller
, add webView
to it. 2)您可以创建新的
controller
,向其中添加webView
。 Then present new controller
within your TableViewController
然后在您的
TableViewController
展示新的controller
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.