【发布时间】:2018-05-25 12:51:24
【问题描述】:
我正在尝试制作一个简单的应用程序将数据从网络映射到表。但该站点需要 OAuth 2.0 的授权和令牌的接收。想要为此以编程方式显示带有 WKWebView 的视图。我这样做:
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
}
}
【问题讨论】:
-
需要同时显示webView和tableView吗?
-
不,表明我需要一些东西。该程序是一个 TableViewController,我想显示一个 WebView 以进行授权并获取令牌(从地址栏)并关闭 WebView。我只是在学习以编程方式创建元素。
标签: ios swift uitableview wkwebview