I am trying to implement the sign up view. This view uses an image picker to check if an image is set, and if all three text fields are not empty and the text view below is not empty, I want to implement a view in which the next button is activated.
I have implemented button activation with three text fields via stackoverflow, but I don't know how to check image view and text view together.
I've tried it for almost a month and I can't think of it in my mind. Any ideas? thanks!
code:
// 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
}
In this picture, I want to activate the button by checking the status of the image view, text field, and text view. But I didn't know how to check all three at once. thank for help