我有44个UIButton,每个按钮都应该使用带有本地html的wkwebview与vc相连。
有没有办法在一个vc中实现所有44个按钮?
这是wkwebview的示例vc的副本
None
答案 0 :(得分:0)
是的,有。您想做两件事:
使用prepare(for segue :)指定要在新VC中打开的URL。 (与新的VC通讯,您要打开哪个URL)
使用该URL打开webkview。
希望这会有所帮助!
实施
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Pass the selected object to the new view controller.
let destVC = segue.destination as! <yourWebkVC>
destVC.address = <exampleAddress>
}
以上表示您要使用的VC yourWebkVC 需要一个类变量“地址”。
根据您单击的按钮,应将 exampleAddress 设置为您希望该按钮打开的任何URL。
您需要在 yourWebkVC
中创建一个变量class yourWebkVC: UIViewController {
var address = String()
您还应该在ViewController中创建一个变量,在该变量中您将来自
class yourBaseViewController: UIViewController {
var url = String()
然后,当您单击每个按钮时,将 url 变量更改为所需的变量。