I am new to swift 3 and have read some part of Ray Wenderlich's iOS apprentice part 3(My Locations). I have pass through the sample code with the hint help of Xcode 8. But when I came to page 120, saying some of selector, I cannot pass through correctly running of Xcode 8. It complaints with error message as following:
2016-10-07 11:10:57.975 test051_MyLocations[2732:65640] -[test051_MyLocations.TagLocationViewController hideKeyboard]: unrecognized selector sent to instance 0x7f96005165f0
The following is my code:
func hideKeyboard(gestureRecognizer: UIGestureRecognizer) {
let point = gestureRecognizer.location(in: tableView)
let indexPath = tableView.indexPathForRow(at: point)
if indexPath != nil && indexPath!.section == 0
&& indexPath!.row == 0 {
return
}
descriptionTextView.resignFirstResponder()
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
descriptionTextView.text = ""
categoryLabel.text = categoryName
latitudeLabel.text = String(format: "%.8f", coordinate.latitude)
longitudeLabel.text = String(format: "%.8f", coordinate.longitude)
if let placemark = placemark {
addressLabel.text = stringFromPlacemark(placemark: placemark)
} else {
addressLabel.text = "No Address Found"
}
dateLabel.text = formatDate(date:Date() as NSDate)
// let hideKeyboard = "hideKeyboard:"
// let selector = Selector(hideKeyboard)
// let selector = Selector({"hideKeyboard:"}())
let gestureRecognizer = UITapGestureRecognizer(target: self,action: Selector({"hideKeyboard"}()))
// I have tried with a : character appended after hideKeyboard, but I still failed to run the program.
gestureRecognizer.cancelsTouchesInView = false
tableView.addGestureRecognizer(gestureRecognizer)
}