如果输入的文本与 Parse 字符串匹配,则在 Button Click 上打开一个新的 ViewController

Open a new ViewController on Button Click if text entered matches Parse string

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

到目前为止,我有一个邮政编码文本字段和一个标记为 "Check Availability" 的按钮。

我有一个 Parse 后端,我使用他们的设置指南测试了与它的连接并且它有效。

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

当前代码:

class checkAvailability: UIViewController {

@IBOutlet weak var zipCode: UITextField!
@IBAction func checkAvailBtn(sender: AnyObject) {
    performSegueWithIdentifier("beginSignUp", sender: self)
}

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
            if let zipCodes = objects as? [PFObject] {
                if zipCodes.contains({ [=11=]["zipCodes"] == usersZipCode) {
                print("your in!") // transition to the new screen
                }
                else {
                print("your out.") // do whatever
                }
                }
            } else {
                // Log details of the failure
                println("Error: \(error!) \(error!.userInfo!)")
            }
        }

override func viewDidLoad() {
    super.viewDidLoad()

    //Code
}

谢谢

创建一个 PFQuery 以将邮政编码列表下拉到应用程序中,然后只需检查用户输入的字符串是否在列表中。

-- 编辑--

    let query = PFQuery(className:"ZipCode")
    query.findObjectsInBackgroundWithBlock {
        (objects: [AnyObject]?, error: NSError?) -> Void in

        if error == nil {
            // The find succeeded.
            print("Successfully retrieved \(objects!.count) zip codes.")
            // Do something with the found objects
            if let zipCodes = objects as? [PFObject] {
                if zipCodes.contains({ [=10=]["zip_code"] as! String == usersZipCode }) {
                    print("your in!") // transition to the new screen
                }
                else {
                    print("your out.") // do whatever
                }
            }
        } else {
            // Log details of the failure
            print("Error: \(error!) \(error!.userInfo)")
        }
    }