我正在尝试实现注册视图。此视图使用图像选择器检查是否设置了图像,如果所有三个文本字段都不为空并且下面的文本视图不为空,我想实现一个激活下一个按钮的视图。
我已经通过stackoverflow实现了三个文本字段的按钮激活,但我不知道如何同时检查图像视图和文本视图。
我已经尝试了将近一个月,但我无法在脑海中想到它。有任何想法吗?谢谢!
代码:
// Properties
@IBOutlet weak var IDTextField: UITextField!
@IBOutlet weak var passwordTextField: UITextField!
@IBOutlet weak var checkPasswordTextField: UITextField!
@IBOutlet weak var textView: UITextView!
@IBOutlet weak var nextButton: UIButton!
// ImagePicker
lazy var imagePicker: UIImagePickerController = {
var picker = UIImagePickerController()
picker.sourceType = .photoLibrary
picker.delegate = self
picker.allowsEditing = true
return picker
}()
@IBOutlet weak var imageView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
IDTextField.addTarget(self, action: #selector(editingChanged(_:)), for: .editingChanged)
passwordTextField.addTarget(self, action: #selector(editingChanged(_:)), for: .editingChanged)
checkPasswordTextField.addTarget(self, action: #selector(editingChanged(_:)), for: .editingChanged)
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
if let image: UIImage = info[UIImagePickerController.InfoKey.editedImage] as? UIImage {
self.imageView.image = image
}
self.dismiss(animated: true, completion: nil)
}
// check TextField
@objc func editingChanged(_ textField: UITextField) {
if textField.text?.count == 1 {
if textField.text?.first == " " {
textField.text = ""
return
}
}
guard
let ID = IDTextField.text, !ID.isEmpty,
let PW = passwordTextField.text, !PW.isEmpty,
let CheckPW = checkPasswordTextField.text, !CheckPW.isEmpty,
PW == CheckPW
else {
nextButton.isEnabled = false
return
}
nextButton.isEnabled = true
}
在这张图片中,我想通过检查图像视图、文本字段和文本视图的状态来激活按钮。但我不知道如何同时检查所有三个。感谢帮助