Trying to pass label text from one view controller to another, however I only want the text from selected labels to be passed across. The labels are chosen by selecting a check box next to it. My attempt is below. I do not receive any errors but I am not seeing the text in the second VC. It doesn't have to be text off a label I just need to pass text that corresponds with the selected check boxes. I have tried with just setting a var. This is my first attempt at programming so I may be missing something very simple. In short need to be able to perform a prepare for segue within an 'if' statement.
First VC
let EnSoString = "Energy Source"
@IBAction func EnergySourceBut(_ sender: UIButton) {
if sender.isSelected {
sender.isSelected = false
} else {
sender.isSelected = true;do {
func prepare(for segue: UIStoryboardSegue, sender: Any){
let receivevc1 = segue.destination as! step4ViewController
receivevc1.EnergySourceLab = EnSoString
}
}
}
}
Second VC
//name
var EnergySourceLab:String?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
// received info
if let receivedEnergySourceLab = EnergySourceLab {
EnergySourceLab1.text = receivedEnergySourceLab}
}
Selecting checkbox Code for prepare for segue within button is.selected