title: how to dismiss keyboard iOS on a table view
body: <p>What is a good way to dismiss this keyboard when the user touches outside of it? I tried the touches began method but this does not work. The textfieldshouldreturn method works okay though. I can't think of any other ways of doing this. Can someone please help me out here I would really appreciate any help. Thanks</p>
  
  <pre><code>import UIKit
  
  
  var courseCatalog : [String] = Array&lt;String&gt;()
  
  
  class HomeViewController: UIViewController, UITextFieldDelegate , UITableViewDelegate{
  
      @IBOutlet var searchTextField: UITextField!
  
  
      override func viewDidLoad() {
  
          courseCatalog = ["Accounting", "Administration" , "American Studies" , "Anthropology" , "Arabic" , "Art" , "Aerospace Studies" , "American Sign Language" , "Biology" , "Child Development" , "Chemistry" , "Chinese" , "Criminal Justice", "Communication Studies" , "Computer Science", "Computer Engineering"]
  
          super.viewDidLoad()
  
          println(PFUser.currentUser())
  
          println("Home Tab View Controller")
  
          searchTextField.delegate = self
      }
  
      func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
  
          return courseCatalog.count
  
      }
  
      func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {
  
          let cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "Cell")
  
          cell.textLabel?.text = courseCatalog[indexPath.row]
  
          return cell
  
      }
  
      override func didReceiveMemoryWarning() {
  
          super.didReceiveMemoryWarning()
  
          // Dispose of any resources that can be recreated.
  
      }
  
  
      override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
  
  
          self.searchTextField.resignFirstResponder()
  
      }
  
      func textFieldShouldReturn(textField: UITextField!) -&gt; Bool {
  
          searchTextField.resignFirstResponder()
          return true
  
      }
  
  
  
  
  
  }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/tUJ5s.png" alt="enter image description here"></p>