我正在尝试通过segue传递一个userID字符串,我知道该怎么做,我将在下面显示我的代码,但是当我尝试使用已设置为segue等于nill的变量时,我想知道为什么会这样以及如何解决它
我为序贯功能做准备
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if (segue.identifier == "go"){
let userID = self.view.viewWithTag(3) as! UILabel
let vc = segue.destination as? selectedListing
vc?.userID = (userID.text!)
}
}
我的viewDidLoad并设置userID变量
var userID : String = ""
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
print("user:"+userID)
}
当我在prepareForSegue中打印出let userID的值时,它会打印我想要的内容,但是当视图加载到已被隔离的单独视图中时,打印为nill