无法在 swift 中的视图控制器和 table 视图控制器之间发送 int 值

Unable to send an int value between view controller and table view controller in swift

class PreferencesViewController 通过 prepare for segue 发送 nil 无论是否采取 IBActions。似乎我为 segue 做的准备有问题,但我不确定。我不是要分配给任何标签或任何东西,我只是想将 int 值发送到 class Pick2_1 中的另一个变量。提前致谢 导入 UIKit

class PreferencesViewController: UIViewController {
    var preference = 0


@IBAction func nImportant(sender: UIButton) {
    preference = -1
    print(preference)
}

@IBAction func N(sender: UIButton) {
    preference = 0
    print(preference)

}

@IBAction func mImportant(sender: UIButton) {
    preference = 1
    print(preference)

}


override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}



override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { 

    if segue.identifier == "preferenceSegue" {
        let preferenceVC = segue.destinationViewController as! Pick2_1
        preferenceVC.preferenceSent = preference
        print(preference)


    }
}
}

Ok segue直接连接到按钮。您必须在您的 2 个控制器之间设置 segue 设置标识符,并且在 @IBAction 中您应该调用 performSegueWithIdentifier func