Reputation: 13
SecondViewController's Code
@IBAction func ContinueFunc(_ sender: AnyObject) {
if (NomeAziendaText.text != "" && NumeroBlocchiText.text != "" && NumeroMacroText.text != ""){
nome = NomeAziendaText.text!
na = Int(NumeroMacroText.text!)!
nb = Int(NumeroBlocchiText.text!)!
Azienda.inizia(name: nome, numbermacro: na, numberblocchi: nb)
self.performSegue(withIdentifier: "next", sender: nil)
}
else {NomeAziendaText.text = ""
NumeroBlocchiText.text = ""
NumeroMacroText.text = ""
LabelAvvisi.text = " Inserisci tutti i valori"
}
/*
// MARK: - Navigation*/
func prepare(for segue: UIStoryboardSegue, sender: Any?) {
print("pippa")
if (segue.identifier == "next"){
if let vc_destinazione = segue.destination as?{
vc_destinazione.stringaDiPassaggio = nome
}
}
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}`
ThirdViewController's Code
import UIKit
class ThirdViewController: UIViewController {
var stringaDiPassaggio: String = String()
var numero: Int = 0
@IBOutlet var Bottone: UIButton!
@IBOutlet var myLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
print(stringaDiPassaggio)
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func FunzioneBottone(_ sender: AnyObject) {
}
}`
Why no data pass from SecondViewController to ThirdViewController? If i override the method PrepareFor segue it show an error which say i doesn't override any method of super class
Help me please
Upvotes: 1
Views: 554
Reputation: 23400
The signature should be
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
}
You have
func prepare(for segue: ...
Upvotes: 1
Reputation: 50
make sure that you have connected the view controllers and correct this
performSegueWithIdentifier("next", sender: self)
then correct this
if (segue.identifier == "next"){
if let vc_destinazione = segue.destination as! ThirdViewController {
vc_destinazione.stringaDiPassaggio = nome
}
}
Upvotes: 1