gpt4 book ai didi

ios - 检查 Parse 数据库以查看输入的文本是否与字符串匹配时出错

转载 作者:行者123 更新时间:2023-11-28 08:58:55 24 4
gpt4 key购买 nike

我正在尝试创建一个按邮政编码显示可用性的注册页面。例如,用户只能在其所在地区(邮政编码)提供该服务时才能注册。

如何检查输入文本以查看它是否与我的 Parse 数据库中的邮政编码匹配?因此,如果用户输入的邮政编码与解析数据库中的邮政编码匹配,我需要一个名为“Register”的新 ViewController 打开,用户可以开始注册/注册。

我当前的代码可以正常工作并切换到新 View 。但我可以在 ZipCode 字段中输入任何内容,它会起作用,我不希望这种情况发生。输出也是“成功检索 0 个邮政编码”。

我的解析预先填充了一个名为 zipCodes 的类和 zipCodes 类中的一个字段,其中还包含我的 20 多个 zipCodes

代码如下:

class checkAvailability: UIViewController {

@IBOutlet weak var zipCode: UITextField!
@IBAction func checkAvailBtn(sender: AnyObject) {
checkZip()
}

func checkZip() {
var usersZipCode = zipCode.text
var queryZip = PFQuery(className: "zipCode")
queryZip.findObjectsInBackgroundWithBlock { (objects:[AnyObject]?, error:NSError?) -> Void in
if error == nil {
// The find succeeded.
println("Successfully retrieved \(objects!.count) zip codes.")
// Do something with the found objects
self.performSegueWithIdentifier("beginSignUp", sender: self)
} else {
println("error")
}
}
}

最佳答案

你必须检查两件事。首先,您正在执行的 error == nil。但还要检查 objects!.count > 0。那是您似乎缺少的部分。

类似于:

queryZip.findObjectsInBackgroundWithBlock { (objects:[AnyObject]?, error:NSError?) -> Void in
if error == nil && objects!.count > 0 {
// The find succeeded.
println("Successfully retrieved \(objects!.count) zip codes.")
// Do something with the found objects
self.performSegueWithIdentifier("beginSignUp", sender: self)
} else {
println("error")
}
}
}

关于ios - 检查 Parse 数据库以查看输入的文本是否与字符串匹配时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32380916/

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