Array类型的值应该通过forceView2
中的stiffView2
传递到prepareForSegue
和ViewController1
。但是,当我在forceView2
中打印时,stiffView2
和ViewController2
都是空的。
任何人都可以解释为什么它在required init
?
ViewController1
@IBAction func solve_Pressed(sender: AnyObject) {
self.performSegueWithIdentifier("Solve", sender: sender)
}
override func prepareForSegue ( segue: UIStoryboardSegue, sender: AnyObject!) {
if (segue.identifier == "Solve") {
var svcViewController2 = segue.destinationViewController as springViewController2
svcViewController2.forceView2 = self.force
svcViewController2.stiffView2 = self.stiffness
}
ViewController2
var forceView2 = [Float]()
var stiffView2 = [Float]()
var forceB1 : Float
var forceB2 : Float
var SpringD : [Float]
required init (coder aDecoder: NSCoder) {
if(isCheckedGlobal) {
(forceB1,forceB2,SpringD) = calculateBoundary(&forceView2, stiffView2, springNum) }
else { println(forceView2)
println(stiffView2)
println(springNum)
SpringD = calculate(forceView2, stiffView2, springNum)
self.forceB1 = forceView2[0]
self.forceB2 = 0.0
}
答案 0 :(得分:2)
在实例化viewController时,init在此行完成:var svcViewController2 = segue.destinationViewController as springViewController2
。此时您的值尚未通过。
例如,您应该尝试println()
viewDidLoad
方法中的var forceView2 = [Float]()
var stiffView2 = [Float]()
var forceB1 : Float
var forceB2 : Float
var SpringD : [Float]
required init (coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override func viewDidLoad() {
super.viewDidLoad()
if(isCheckedGlobal) {
(forceB1,forceB2,SpringD) = calculateBoundary(&forceView2, stiffView2, springNum) }
else {
println(forceView2)
println(stiffView2)
println(springNum)
SpringD = calculate(forceView2, stiffView2, springNum)
self.forceB1 = forceView2[0]
self.forceB2 = 0.0
}
}
数据。
修改:
我现在不能尝试,但你应该尝试这样的事情:
{{1}}
如果需要,请不要忘记查看您的房产(可选,零,......)。