I have searched through the net for couple of hours now thought this would be an easy task, but things are not going as planned. This question is edited, some of great fella has given great answer but I am still struggling.
Here is the scenario, I have a viewControllerA which is always visible. There is a small button on top of this view, when I click it there comes viewControllerB as a static tableViewController. Its a slide view from left to right to be honest like other apps.
There is one section and couple of rows in the tableView, when I tap 4th row I present viewControllerC, there is a UISwitch button there. When I dismiss the viewControllerC, viewControllerA appear again. viewControllerB is my menu controller therefore its not my greater concern .Now I want to pass data from viewControllerC to viewControllerA. Here is my broken code:
for viewControllerC :
class viewControllerC: UIViewController {
..//
@IBAction func switchTapped(_ sender: UISwitch) {
let vc = viewControllerA()
if sender.isOn == true {
vc.state = true
} else if sender.isOn == false {
vc.state = false
}
}
..//
}
for viewControllerA :
class viewControllerA: UIViewController, GMSMapViewDelegate {
var state:Bool?
...//
if self.state == true {
self.mapView.isTrafficEnabled = true
} else {
self.mapView.isTrafficEnabled = false
}
}
But its not working an I know I am not heading to the right direction. As you can see from the example I want to send ture when UISwitch is on and false when its off from viewControllerC to viewControllerA. Some of the folks have suggested delegate method but I am still struggling. I was following this link , I think "Passing data backwards through the shared state of the app" section meets my criteria. Although I need help. Thanks in advance.