ios - 覆盖 prepareForSegue 不起作用

标签 ios swift

SecondViewController 的代码

@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 的代码

 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) {

}

}`

为什么没有数据从 SecondViewController 传递到 ThirdViewController? 如果我重写 PrepareFor segue 方法,它会显示一个错误,表明我没有重写父类(super class)的任何方法

请帮帮我

最佳答案

确保您已连接 View Controller 并更正此错误

          performSegueWithIdentifier("next", sender: self)

然后改正这个

 if (segue.identifier == "next"){
    if let vc_destinazione = segue.destination as! ThirdViewController {


        vc_destinazione.stringaDiPassaggio = nome
    }

}

关于ios - 覆盖 prepareForSegue 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39664398/

相关文章:

ios - 可能性数组的(快速)

ios - CC动画缓存 : how should I use it?

ios - SQLite 插入 boolean 值

ios - 为 iPhone 应用程序构建 ScrollView 页面

swift - 499.28999999999996 -> 499.28 如何删除小数点而不四舍五入?

ios - Swift iOS - 如何实现多行不同字号的SegmentedControl

ios - 架构 armv7 错误的重复符号

ios - 在 SwiftUI 中获取文本的宽度

swift - 节点在 Sprite Kit 中变慢

ios - 如何以编程方式将下一个 View Controller 推送到导航 Controller 上?