By passing a value to the variable var of the transition destination at the time of screen transition, you can pass the value to another screen.
ViewController
let secondViewController = self.storyboard?.instantiateViewController(withIdentifier: "second") as! secondViewController
secondViewController. value = "value"
self.present(secondViewController, animated: true, completion: nil)
secondViewController
class secondViewController: UIViewController {
var value = String()
override func viewDidLoad() {
super.viewDidLoad()
}
}
Because tabBarController creates a screen when you first switch tabs and does not delete it You need a way to pass a value other than at the time of screen transition.
You can pass a value or perform a process to another screen by using a protocol to execute it after a specific process.
ViewController
var process: anotherScreenProcess!
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.process = secondViewController() as anotherScreenProcess
self.process.sendValue()
}
}
secondViewController
protocol anotherScreenProcess {
func sendValue()
}
class secondViewController: UIViewController, anotherScreenProcess {
override func viewDidLoad() {
super.viewDidLoad()
}
//Processing from another screen
func sendValue() {
}
}
tabBarController creates a screen only at the first screen transition and is not deleted. Therefore, by deleting the tabBarController created other than using the protocol, You can recreate the screen itself.
python
self.tabBarController!.viewControllers![1].dismiss(animated: true, completion: nil)
Recommended Posts