I am attempting to display 5 web views and I would like the web views to be created in a for loop. The code I am currently using creates only one web view where it should create one for every url in pages. Any help would be appreciated!
import UIKit
import Foundation
import WebKit
import AVFoundation
class displayviews: UIViewController, WKUIDelegate {
var pages = ["https://example.com", "https://example", "https://example", "https://example.com", "https://example.com"]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
for i in pages{
var inti = Int(i) ?? 0
//var currentwebview = String("webView") + i
let myWebView:WKWebView = WKWebView(frame: CGRect(x:0, y:CGFloat(inti*200), width: UIScreen.main.bounds.width, height:UIScreen.main.bounds.height/CGFloat(pages.count)))
myWebView.uiDelegate = self
self.view.addSubview(myWebView)
//1. Load web site into my web view
let myURL = URL(string: pages[inti])
let myURLRequest:URLRequest = URLRequest(url: myURL!)
myWebView.load(myURLRequest)
}
}
}