Я создаю поток входа в систему и повторно использую свои текстовые поля. Я хочу знать, что я делаю неправильно в этом отношении или как я могу изменить проверку в текстовом поле. Я создал счетчик, чтобы посмотреть, поможет ли это определить параметры для этого счета. Когда я получаю подтверждение по электронной почте, оно работает неправильно. Независимо от того, что я ввожу, я получаю предупреждение.
final class SignupViewController: UIViewController, ViewPassesData, UITextFieldDelegate {
@IBOutlet weak var firstNameTextField: UITextField!
@IBOutlet weak var lastNameTextField: UITextField!
@IBOutlet weak var backgroundViewImage: UIImageView!
@IBOutlet weak var firstLabel: UILabel!
@IBOutlet weak var secondLabel: UILabel!
@IBOutlet weak var button: UIButton!
@IBOutlet weak var secondLine: UIView!
enum SignUpStage {
case name
case email
case password
case phone
case text
case notifications
case location
}
var stage: SignUpStage?
var dictionary: [String: String] = [:]
override func viewDidLoad() {
super.viewDidLoad()
setLayoutForStage()
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
firstNameTextField.resignFirstResponder()
lastNameTextField.resignFirstResponder()
}
func isValidEmail(email:String) -> Bool {
let emailRegEx = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}"
let emailTest = NSPredicate(format:"SELF MATCHES %@", emailRegEx)
let result = emailTest.evaluate(with: email)
return result
}
func isPasswordValid(text: String) -> Bool {
let passWordRegEx = "[A-Z0-9a-z]{0,9}"
let passwordTest = NSPredicate(format:"SELF MATCHES %@", passWordRegEx)
let result = passwordTest.evaluate(with: text)
return result
}
@IBAction func validationTextField(_ sender: UITextField) {
}
Здесь у меня проблемы с моим кодом. - Обновление Я исправил проблему с помощью комментария @Julio Cesar Arregoitía Val.
@IBAction func actionButtonPressed(_ sender: UIButton) {
guard let vc = storyboard?.instantiateViewController(withIdentifier: "Signup") as? SignupViewController, let stage = nextStage() else { return }
vc.stage = stage
setDictionaryValues()
switch currentStage {
case .name:
if firstNameTextField.text == "" || lastNameTextField.text == "" {
alertMessage()
}
else {
vc.dictionary = dictionary
self.navigationController?.pushViewController(vc, animated: true)
}
case .email:
currentStage = .email
if isValidEmail(email: "\(firstNameTextField.text!)") == true {
vc.stage = stage
vc.dictionary = dictionary
self.navigationController?.pushViewController(vc, animated: true)
}
else {
alertMessage()
}
case .password:
currentStage = .password
if firstNameTextField.text != "" && isPasswordValid(text: "\(firstNameTextField.text!)") == true {
vc.stage = stage
vc.dictionary = dictionary
self.navigationController?.pushViewController(vc, animated: true)
}
else {
alertMessage()
}
case .phone:
currentStage = .phone
case .text:
currentStage = .text
case .notifications:
currentStage = .notifications
case .location:
currentStage = .location
}
}
@IBAction func back(_ sender: Any) {
navigationController?.popViewController(animated: true)
}
private func setLayoutForStage() {
guard let stage = stage else { return }
switch stage {
case .name:
firstLabel.text = "first name".uppercased()
secondLabel.text = "last name".uppercased()
case .email:
firstLabel.text = "email".uppercased()
secondLabel.isHidden = true
lastNameTextField.isHidden = true
secondLine.isHidden = true
case .password:
button.setNeedsDisplay()
firstLabel.text = "password".uppercased()
firstNameTextField.isSecureTextEntry = true
secondLabel.isHidden = true
lastNameTextField.isHidden = true
secondLine.isHidden = true
case .phone:
firstLabel.text = "phone number".uppercased()
firstNameTextField.keyboardType = .numberPad
secondLabel.isHidden = true
lastNameTextField.isHidden = true
secondLine.isHidden = true
case .text: break
case .notifications: break
case .location: break
}
}
func resetTextFields() {
}
func setDictionaryValues() {
guard let stage = stage else { return }
switch stage {
case .name:
dictionary["first_name"] = firstNameTextField.text?.capitalizingFirstLetter()
dictionary["last_name"] = lastNameTextField.text?.capitalizingFirstLetter()
case .email:
dictionary["email"] = firstNameTextField.text
firstNameTextField.text = ""
case .password:
dictionary["password"] = firstNameTextField.text
dictionary["password_confirmation"] = firstNameTextField.text
case .phone:
dictionary["phone_number"] = firstNameTextField.text
dictionary["contact_preference"] = "EMAIL"
case .text: break
case .notifications: break
case .location: break
}
}
// TODO: make this all one system
private func nextStage() -> SignUpStage? {
guard let stage = stage else { return .name }
switch stage {
case .name: return .email
case .email: return .password
case .password: return .phone
case .phone:
guard let nextVC = storyboard?.instantiateViewController(withIdentifier: "text") as? TextPhoneViewController, firstNameTextField.text?.count == 10 else {
return nil
}
nextVC.dictionary = dictionary
self.navigationController?.pushViewController(nextVC, animated: true)
return nil
case .text: return nil
case .notifications: return nil
case .location: return nil
}
}
}