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
import UIKit
var courseCatalog : [String] = Array<String>()
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) -> Int {
return courseCatalog.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> 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!) -> Bool {
searchTextField.resignFirstResponder()
return true
}
}