gpt4 book ai didi

ios - 在 Swift 中使用 for 循环完成

转载 作者:行者123 更新时间:2023-11-28 10:46:23 25 4
gpt4 key购买 nike

我正在尝试使用 Firebase 编写一个函数,它允许知道用户名是否被占用。

for username in dict.values {
if username as? String == self.usernameText.text! {
appDelegate.visualReturnBottom(message: "Username already taken.", color: brandBlue, backgroundColor: UIColor.white)
return
}
}

问题是,如果没有使用用户名,我想更改 View Controller 。为此,我必须等待循环结束,我真的不知道该怎么做。

我想添加这部分代码“如果循环结束......:”

let nextVC = self.storyboard?.instantiateViewController(withIdentifier: "InscriptionSecondVC") as! Inscription2TableViewController

self.navigationController?.pushViewController(nextVC, animated: true)

最佳答案

如果您正在检查用户名匹配值的字典,则必须等到循环完成。没有其他方法可以执行该检查。由于您的代码目前已构成,这应该可以工作。

for username in dict.values {
if username as? String == self.usernameText.text! {
appDelegate.visualReturnBottom(message: "Username already taken.", color: brandBlue, backgroundColor: UIColor.white)
return
}
}

// if the username is already taken, you will never reach this point.
let nextVC = self.storyboard?.instantiateViewController(withIdentifier: "InscriptionSecondVC") as! Inscription2TableViewController

self.navigationController?.pushViewController(nextVC, animated: true)

至于Dan's answer ,我同意,你应该考虑重组你的数据。这只是对您的具体问题的回答。

关于ios - 在 Swift 中使用 for 循环完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48386048/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com