title: I have an sigabbt error that says this Terminating app due to uncaught exception 'NSInvalidArgumentException'
body: <p>Hello I am trying to complete the element quiz app on the Develop in swift explorations booklet on iBooks for Xcode, and I keep getting 2 constant errors that won't go away whenever I press the &quot;show answer&quot; button the app just crashes and gives me this error'</p>
  <blockquote>
  <p>Terminating app due to uncaught exception
  'NSInvalidArgumentException', reason: '-[ElementQuiz.ViewController
  showAnswer:]: unrecognized selector sent to instance 0x7fddca6059f0'</p>
  </blockquote>
  <p>here is my code</p>
  <pre><code>import UIKit
  enum Mode {
      case flashCard
      case quiz
  }
  enum State {
      case question
      case answer
      case score
  }
  class ViewController: UIViewController,
  UITextFieldDelegate {
  
      override func viewDidLoad() {
          super.viewDidLoad()
          updateUI()
          
      }
      
      let elementList = [&quot;Carbon&quot;, &quot;Gold&quot;, &quot;Chlorine&quot;, &quot;Sodium&quot;]
      var currentElementIndex = 0
      var state: State = .question
      var answerIsCorrect = false
      var correctAnswerCount = 0
      var mode: Mode = .flashCard {
          didSet {
              updateUI()
          }
      }
      @IBOutlet weak var imageView: UIImageView!
      @IBOutlet weak var answerLabel: UILabel!
      
      @IBAction func showAnswer() {
          state = .answer
          updateUI()
      }
      @IBAction func next(_ sender: Any) {
          if currentElementIndex == elementList.count {
              currentElementIndex = 0
              if mode == .quiz {
                  state = .score
                  updateUI()
                  return
              }
          }
          state = .question
          
          updateUI()
      }
      @IBOutlet weak var modeSelector: UISegmentedControl!
      
      @IBOutlet weak var textField: UITextField!
      
      @IBAction func switchModes(_ sender: Any) {
          if modeSelector.selectedSegmentIndex == 0 {
              mode = .flashCard
          } else {
              mode = .quiz
          }
          var mode: Mode = .flashCard {
              didSet {
                  updateUI()
              }
          }
      }
      func textFieldShouldReturn(_ textField: UITextField) -&gt; Bool {
          let textFieldContents = textField.text!
          
          if textFieldContents.lowercased() == elementList[currentElementIndex].lowercased() {
              answerIsCorrect = true
              correctAnswerCount += 1
          } else {
              answerIsCorrect = false
          }
          state = .answer
          
          updateUI()
          
          return true
      }
  
      func updateFlashCardUI(elementName: String) {
          textField.isHidden = false
          textField.resignFirstResponder()
          if state == .answer {
              answerLabel.text = elementName
              } else {
                  answerLabel.text = &quot;?&quot;
              }
          modeSelector.selectedSegmentIndex = 0
          }
      func updateQuizUI(elementName: String) {
          textField.isHidden = false
          switch state {
          case .question:
              textField.text = &quot;&quot;
              textField.becomeFirstResponder()
          case .answer:
              textField.resignFirstResponder()
          case .score:
              textField.isHidden = true
              textField.resignFirstResponder()
          }
          switch state {
          case .question:
              answerLabel.text = &quot; &quot;
          case .answer:
              if answerIsCorrect {
                  print(&quot;Correct!&quot;)
              } else {
                  print(&quot;Incorrect!&quot;)
              }
              
          case .score:
              answerLabel.text = &quot;&quot;
              print(&quot;Your score is \(correctAnswerCount) out of \(elementList.count).&quot;)
  
          }
          if state == .score {
              displayScoreAlert()
          }
          modeSelector.selectedSegmentIndex = 1
      }
      func updateUI() {
          let elementName =
             elementList[currentElementIndex]
          let image = UIImage(named: elementName)
          imageView.image = image
          if state == .answer {
              answerLabel.text = elementName
          } else {
              answerLabel.text = &quot;?&quot;
          }
          switch mode {
          case .flashCard:
              updateFlashCardUI(elementName: elementName)
          case .quiz:
              updateQuizUI(elementName: elementName)
          }
      }
      func displayScoreAlert() {
          let alert = UIAlertController(title: &quot;Quiz Score&quot;, message: &quot;Your score is\(correctAnswerCount)out of \(elementList.count).&quot;, preferredStyle: .alert)
          let dismissAction = UIAlertAction(title: &quot;OK&quot;, style: .default, handler: scoreAlertDismissed(_:))
          alert.addAction(dismissAction)
          
          present(alert, animated: true, completion: nil)
      }
      func scoreAlertDismissed(_ action: UIAlertAction) {
          mode = .flashCard
      }
      }
  </code></pre>
  <p>another error is when I press flash cards then quiz then back to flashcards the app crashes and gives me this error</p>
  <blockquote>
  <p>Terminating app due to uncaught exception
  'NSInvalidArgumentException', reason: '-[ElementQuiz.ViewController
  textField:]: unrecognized selector sent to instance 0x7fb402d028a0'</p>
  </blockquote>
  <p>can anyone help me fix these errors? thanks</p>