ios - 使用 FPSignup ViewController 注册/解析时小写所有条目

标签 ios swift parse-platform

我正在使用 Parse.com 提供的默认注册/登录 View Controller 。

我让它工作,但我希望文本字段响应小写所有条目,如果可能,使用下划线 (_) 作为空格。

过去一天我一直在研究这个,但没有在网上找到任何有用的东西。

class ViewController: UIViewController, PFLogInViewControllerDelegate, PFSignUpViewControllerDelegate, UITextFieldDelegate {

var logInViewcontroller: PFLogInViewController! = PFLogInViewController()
var signUpViewController: PFSignUpViewController! = PFSignUpViewController()

override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(animated)

    if (PFUser.currentUser() == nil){
        self.logInViewcontroller.fields = PFLogInFields.UsernameAndPassword | PFLogInFields.LogInButton | PFLogInFields.SignUpButton | PFLogInFields.PasswordForgotten | PFLogInFields.DismissButton
        self.logInViewcontroller.delegate = self            
        self.signUpViewController.delegate = self
        self.logInViewcontroller.signUpController = self.signUpViewController
        self.logInViewcontroller.logInView?.usernameField!.delegate = self
    } else {
        self.performSegueWithIdentifier("logedIn", sender: self) //use found: moving forward
    }
    presentViewController(self.logInViewcontroller, animated: true, completion: nil)        
}

func signUpViewController(signUpController: PFSignUpViewController, shouldBeginSignUp info: [NSObject : AnyObject]) -> Bool {
    return true
}

func signUpViewController(signUpController: PFSignUpViewController, didSignUpUser user: PFUser) {
    self.dismissViewControllerAnimated(true, completion: nil)
}

我已经设置了一个 UITextFieldDelegate,但不确定如何连接两者。 我想我应该使用这个...

func textFieldShouldEndEditing(textField: UITextField) -> Bool {

    if (textField == self.logInViewcontroller.logInView?.usernameField) { 
        textField.text = textField.text.lowercaseString
        return false // false or true?
    }
}

还有其他人遇到过这个问题吗?

最佳答案

除了使用 UITextField 委托(delegate),您还可以将目标添加到文本字段以更改控件事件编辑:

在viewDidAppear中

而不是这个“

self.logInViewcontroller.logInView?.usernameField!.delegate = self

添加这个:

self.logInViewcontroller.logInView?.usernameField.addTarget(self, action: "textChanged:", forControlEvents: .EditingChanged)

并添加你的方法来操作字符串:

func textChanged(sender: UITextField) {
    sender.text = sender.text!.lowercaseString.stringByReplacingOccurrencesOfString(" ", withString: "_")
}

顺便说一句,里奥来了。 :)

关于ios - 使用 FPSignup ViewController 注册/解析时小写所有条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32800973/

相关文章:

javascript - 在 Parse 中检索字符串

ios - 如何在 swift 3 中按下按钮时转到另一个 View Controller

ios - 计算 PFRelation 中的对象数

installation - Parse.com - 查询安装表返回 0,即使表中有两个条目

Android parse.com 收不到推送通知

ios - 在 cellForRowAtIndexPath 中重新排序 collectionViewCells 的目标

ios - Apple Watch 在 15 分钟后失去与 iOS 应用程序的连接

ios - 是否可以找到也有Apple设备的用户的联系人?

ios - 无法将自定义字体添加到 Xcode

ios - Swift 中每秒在随机 CGPoint 处生成 UIView