Reputation: 3
I'm begginer for swift. I want to create the web view application optimized navigation (to see commerce site).
I decide to use TabBarController
(with 6 tabs) and UIWebView
. And I could implement this application.
TabBarController
related to 6 ViewControllers
ViewControllers
has each UIWebView
(specified URI)I could see 6 tabs like website. But I have question...
ViewController
have each UIWebView
)UIWebView
generated in diffrent timing have same session?(must have same session)If possible, I want to use a TabBarController
with 6 tab and a ViewController
and a UIWebView
.
And when I could select a tab(in 6tabs), I want to change the url of the same UIWebView
.
Please tell me how to solve this. Thanks in advance.
Upvotes: 0
Views: 1396
Reputation: 2120
I think, it is not possible to have one ViewController
in TabBarController
, but you can have one WebView
and share it between your view controllers.
Create WebView in singleton style:
class WebView: UIWebView
{
static let sharedInstance = WebView()
}
Place it on view, that will appear on screen:
class FirstViewController: UIViewController
{
override func viewWillAppear(animated: Bool)
{
view.addSubview(WebView.sharedInstance)
WebView.sharedInstance.frame = CGRect(x: 0, y: 0, width: 320, height: 480)
// configure it as you need: load request, setup autolayout constraints, etc..
}
}
class SecondViewController: UIViewController
{
override func viewWillAppear(animated: Bool)
{
view.addSubview(WebView.sharedInstance)
WebView.sharedInstance.frame = CGRect(x: 0, y: 0, width: 320, height: 480)
// same
}
}
// and same in each view controller
Upvotes: 1