我的 firstVC json 包含所有其他视图控制器 json id...在这里我想要在推送到其他视图控制器之前我需要将它与 home home json id 进行比较,这 2 个 id 相同我需要推送 thatVC .. 所以这里不用去任何其他视图控制器我们如何让他们的 id 在 homeVC 中进行比较...请在这里帮助我。
我尝试了两种方法:
1) 在 secondVC 中声明变量并为其分配 secondVC id 值并在 firstVC 中调用它
在 firstVC 代码中:
let goVC = self.storyboard?.instantiateViewController(withIdentifier: "SecondViewController") as? SecondViewController
var goId: String = goVC.secndId ?? ""
print("the goid is \(goId)")// getting nil
if(goId == allIdArray)
{
self.navigationController?.pushViewController(goVC, animated: true)
}
在 secondVC 中:
var secndId: String?
secndId = jsonObj["sid"] as? String
2) 使用钥匙串包装器存储 secondVC json id 并在 firstVC 中检索它
在第一:
let goVC = self.storyboard?.instantiateViewController(withIdentifier: "SecondViewController") as? SecondViewController
let goId: String = KeychainWrapper.standard.string(forKey: "sid") ?? ""
print("the goid is \(goId)")// getting nil
if(goId == allIdArray)
{
self.navigationController?.pushViewController(goVC, animated: true)
}
在 secondVC 中:
var secndId: String?
self.secndId = jsonObj["sid"] as? String
KeychainWrapper.standard.set(self.secndId ?? "", forKey: "sid")
这里 allIdArray 包含 allVC id,而 sid 是 secondVC json id
在这两种方式我都得到零为什么?我想比较 firstvc 中的 secondvc id 而不去 secondvc。
请在上面的代码中帮助我。