Answer the question
In order to leave comments, you need to log in
Why doesn't data transfer between VCs work in the opposite direction when clicking on the Bar button item?
Good day! There are two VCs from the second you need to transfer data, the transition to the second is done with the button on the navigation bar. But if the button is on the bar, then the data transfer stops working. How to fix it?
1 VC
import UIKit
class FitstVC: UIViewController {
@IBOutlet var textLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func saveData(_ sender: UIStoryboardSegue) {
if let sourceViewController = (sender as AnyObject).source as? SecondVC {
textLabel.text = sourceViewController.text
}
}
}
import UIKit
class SecondVC: UIViewController {
var text = ""
@IBOutlet var textLabel: UILabel!
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
text = "code"
}
override func viewDidLoad() {
super.viewDidLoad()
}
}
Answer the question
In order to leave comments, you need to log in
What triggers your action? If the button is back - the method is not called .
In the second controller, there is no data transfer to the first controller at all. You need to use delegates
for your task .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question