Data Transfer Between Controllers in iOS on Swift: Best Practices
Hello everyone! I'm a beginner in iOS development with Swift and I can't figure out data transfer between View Controllers. I've read a ton of articles, but I'm still confused.
I have two screens: the first one (MainViewController) has a text field and a button, the second one (DetailViewController) has a label that should display the entered text. I'm creating a segue through Storyboard, but the data isn't being transferred.
Here's my code:
class MainViewController: UIViewController {
@IBOutlet weak var textField: UITextField!
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "showDetail" {
let detailVC = segue.destination as! DetailViewController
detailVC.receivedText = textField.text
}
}
@IBAct No answers yet.
Log in to leave an answer