我是swift 3的新手,并且已经阅读了Ray Wenderlich的iOS学徒第3部分(My Locations)的某些部分。我已经通过Xcode 8的提示帮助传递了示例代码。但是当我来到第120页,说一些选择器时,我无法正确运行Xcode 8.它投诉错误消息如下:
2016-10-07 11:10:57.975 test051_MyLocations [2732:65640] - [test051_MyLocations.TagLocationViewController hideKeyboard]:无法识别的选择器发送到实例0x7f96005165f0
以下是我的代码:
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)
}