gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 02:18:58 26 4
gpt4 key购买 nike

我正在使用 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/

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