我用這庫爲SEARCHTEXT現場UITapGestureRecognizer在Swift中打破SearchField類中的UITableView didSelectRowAtIndexPath?
https://github.com/apasccon/SearchTextField
這裏是我的代碼:
override func viewDidLoad() {
super.viewDidLoad()
self.view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: Selector("dismissKeyboard")))
}
func dismissKeyboard()
{
ClientList.resignFirstResponder()
self.view.endEditing(true)
}
關閉鍵盤的工作,但didSelectRowAtIndexPath方法是沒有得到調用,所以我不能夠選擇任何東西
部分解決我做:
func hideKeyboard(gestureRecognizer: UIGestureRecognizer) {
let point = gestureRecognizer.locationInView(ClientList.tableView)
let indexPath = ClientList.tableView!.indexPathForRowAtPoint(point)
if indexPath != nil {
return
}
if ClientList.becomeFirstResponder() {
ClientList.resignFirstResponder()
}
}
但現在的問題是,我有其他列表也一樣,我怎麼能實現對其他列表?
只需將函數更新爲** Swift 3 ** 'func gestureRecognizer(_ gestureRecognizer:UIGestureRecognizer,shouldReceive touch:UITouch) - > Bool {0}如果touch.view != nil && touch.view!.isDescendant(of:self.tableView){ return false } return true }'' –