swift - Not able to load WebView on button click -
i trying load url on dynamically created webview when user clicks on button nothing loads.
code :
import cocoa import webkit class viewcontroller :nsviewcontroller { override func viewdidload() { super.viewdidload() // additional setup after loading view. } override var representedobject: any? { didset { // update view, if loaded. } } @ibaction func mybutton(_ sender: any) { let url = url(string: "https://www.google.com") let request = urlrequest(url: url!) let webview = webview(frame: nsrect(x: 0, y: 0, width: 400, height: 400)) webview.mainframe.load(request) } }
you still have add webview subview of viewcontroller:
@ibaction func mybutton(_ sender: any) { let url = url(string: "https://www.google.com") let request = urlrequest(url: url!) let webview = webview(frame: nsrect(x: 0, y: 0, width: 400, height: 400)) webview.mainframe.load(request) self.view.addsubview(webview) }
wiki
Comments
Post a Comment