【发布时间】:2018-04-09 18:08:32
【问题描述】:
我有 2 个VC:
FirstVc 因为我有一个文本字段 NamesTF 。
secondVC 我需要检查FirstVc 中的NamesTF 是否有值。如果值可用我的bool 值必须来True。如果值不可用bool 值必须来False
我的代码:
FirstVc:
let storyboard = UIStoryboard(name: "DashBoard", bundle: nil)
let destinationVc = storyboard.instantiateViewController(withIdentifier: "SecondVC")
if NamesTF.text == "" {
SecondVC.NameAvailable = false
self.navigationController?.pushViewController(destinationVc, animated: true)
}
else
{
SecondVC.NameAvailable = false
self.navigationController?.pushViewController(destinationVc, animated: true)
}
在我的SecondVC:
var NameAvailable = false
override func viewWillAppear(_ animated: Bool) {
if NameAvailable == true {
// print the name
}
else {
// no name availble //false
}
}
我做错了什么。谁能帮帮我。
谢谢~
【问题讨论】:
-
这些
SecondVC和AllOperatorNewVC来自哪里? -
@Adeel 抱歉,这是我的代码错误。现在我有一个正确的。请查看我的帖子。
-
这仍然没有意义。您在
SecondVC中设置Bool并推送destinationVc。在destinationVc中设置布尔值,像这样destinationVc.NameAvailable = true。 -
@david 传递值的概念永远不会改变 bool、string、array 等。