here is my situation
I have this setup,
UIWebView webView
ViewControllerA {
IBOutlet weak var webView : UIWebView
override viewDidLoad {
doSomething()
}
}
ViewControllerB {
IBOutlet weak var webView : UIWebView (different instance! wrong)
override viewDidLoad {
doSomethingDifferent()
}
}
I use Tab Bar controller to move from viewA to viewB and I want to move my webView from viewA to viewB so I can show the exact same web page with different information at the bottom of the view depending if im in viewA or viewB
since the webview could play a video, I want this video to be playing in both views at the same time so I can't reload the webView, just move it.
Any ideas to achieve that? Already tried container views but it s'till two different instances of the UIWebView... is it possible to do it in interface builder or in swift?
The below code is unsafe due to force unwrapping, but you can use it as a reference. I've declared globalWebView
as a global variable.
First view controller:
var globalWebView: UIWebView?
class FirstViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
globalWebView = UIWebView(frame: CGRectMake(20, 30, 300, 300))
globalWebView?.loadRequest(NSURLRequest(URL: NSURL(string: "https://www.youtube.com/embed/XLpDiIVX0Wo")!))
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
self.view.addSubview(globalWebView!)
}
}
Second view controller:
class SecondViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
self.view.addSubview(globalWebView!)
}
}