类首选项viewcontroller通过prepare for segue发送nil,无论是否执行ibactions。似乎我在准备赛格时出了点问题,但我不确定。我没有试图分配给任何标签或任何东西,我只是试图将int值发送给类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直接连接到按钮。您必须在两个控制器之间设置segue设置标识符,在@ibaction中,您应该调用performseguewithidentifier func