当我选择任何行而不是调用时,没有被调用。它的颜色在选择时也会变为蓝色。但didSelect不工作.Delegate,DataSources和Table outlet也相连。这是我的代码:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
categoryLbl.text = categoryArray[indexPath.row].type
dataDict.setValue(categoryArray[indexPath.row].type, forKey: "category")
categoryTable?.isHidden = true
}
override func viewDidLoad() {
super.viewDidLoad()
imagePicker.delegate = self
NotificationCenter.default.addObserver(self, selector: #selector(self.keyboardNotification(notification:)), name: NSNotification.Name.UIKeyboardWillChangeFrame, object: nil)
categoryTable?.isHidden = true
self.geCategoryData()
let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action:#selector(AddFeedbackViewController.dismissKeyboard))
view.addGestureRecognizer(tap)
}
答案 0 :(得分:3)
试试这个,它会解决你的问题
tap.delegate = self // add this in viewdidLoad()
extension YourViewContoller: UIGestureRecognizerDelegate {
func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -> Bool {
if touch.view != nil && touch.view!.isDescendantOfView(self.tableView) {
return false
}
return true
}
}
答案 1 :(得分:0)
试试这个,
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
categoryLbl.text = categoryArray[indexPath.row].type
dataDict.setValue(categoryArray[indexPath.row].type, forKey: "category")
categoryTable?.isHidden = true
}