我正试图从我的一个视图控制器的swift文件中获取这些变量:
//global
let choice1Box1 = drivingGear[chooseDrivingGear.selectedRow(inComponent: 0)]
let choice2Box1 = drivingGear[chooseDrivenGear1.selectedRow(inComponent: 0)]
这是对原始类中的变量做了什么:
@IBAction func showResultBox1(_ sender: Any) {
let choice1Box1 = self.drivingGear[self.chooseDrivingGear.selectedRow(inComponent: 0)]
let choice2Box1 = self.drivingGear[self.chooseDrivenGear1.selectedRow(inComponent: 0)]
if let intVal1 = Double(choice1Box1), let intVal2 = Double(choice2Box1) {
result = intVal2 / intVal1
let newLabel = String(result)
resultBox1.setTitle(newLabel, for: .normal)
}
}
答案 0 :(得分:1)
就这样做:
从pickerView中选择值后。像这样传递它。
对于Eg。您需要将String传递给下一个VC:
在SecondVC中:在这里声明一个值:
var strFromPreviousVC:String = String()
在第一个VC中:像这样发送值:
let objSecondVC = self.storyboard?.instantiateViewController(withIdentifier: "secondVC") as! SecondVC
objSecondVC.strFromPreviousVC = "your selected String here"
self.navigationController?.pushViewController(objSecondVC, animated: true)
是的,它已完成,它将传递给SecondVc,您可以在SecondVc中使用print(strFromPreviousVC)
之类的值
希望它有所帮助。