5 Replies
      Latest reply on Apr 30, 2018 6:38 AM by John368
      john217 Level 1 Level 1 (0 points)

        I was trying to follow developer app guide to create a very simple app.

         

        I have a textfield and when I'm finished typing I will click on DONE button which will result in hiding the keyboard. my problem is that after the first time this happens the keyboard won't show again no matter how many times I tap/click on the textfield

         

        here is my code

        :

         

        
        

         

        import UIKit

        class ViewController: UIViewController, UITextFieldDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate {

            /

          

            @IBOutlet weak var nameTextField: UITextField!

            @IBOutlet weak var mealNameLabel: UILabel!

            @IBOutlet weak var photoImageView: UIImageView!

            override func viewDidLoad() {

                super.viewDidLoad()

              

                nameTextField.delegate = self

            }

          

            func textFieldShouldReturn(_ textField: UITextField) -> Bool {

              

                /

                textField.resignFirstResponder()

                return true

            }

          

            func textFieldDidEndEditing(_ textField: UITextField) {

                mealNameLabel.text = textField.text

            }

          

            func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {

                /

              

                dismiss(animated: true, completion: nil)

              

            }

          

            func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {

                /

              

                guard let selectedImage = info[UIImagePickerControllerOriginalImage] as? UIImage else {

                    fatalError("Expected a dictionary containing an image, but was provided the following: \(info) ")

                }

              

                photoImageView.image = selectedImage

              

                dismiss(animated: true, completion: nil)

            }

            /

          

            @IBAction func selectImageFromPhotoLibrary(_ sender: UITapGestureRecognizer) {

              

                /

                nameTextField.resignFirstResponder()

              

                /

                let imagePickerController = UIImagePickerController()

              

                /

                imagePickerController.sourceType = .photoLibrary

              

                /

                imagePickerController.delegate = self

              

                present(imagePickerController, animated: true, completion: nil)

            }

            @IBAction func setDefaultLabelText(_ sender: UIButton) {

                mealNameLabel.text = "Default Text"

            }

          

          

        }