ios - UITableView didSelect 在 swift 3.0 中不起作用

标签 ios iphone swift

当我选择任何行时,没有调用 didselect。它的颜色也会在选择时变为蓝色。但 didSelect 不起作用。Delegate、DataSources 和 Table 导出也已连接。这是我的代码:

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)

}

最佳答案

试试这个,它会解决你的问题

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
    }
}

关于ios - UITableView didSelect 在 swift 3.0 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43025900/

相关文章:

ios - 在 Swift 3/Xcode 8 (SharkORM) 中安装第三方 Objective-C 库

ios - 将 UIView.layer.clipsToBounds = true 与 CABasicAnimation 结合使用时,并非所有像素都被剪裁

ios - "Collection View"的框架在运行时会有所不同 Swift3 iOS10 StoryBoard

iOS:具有动态单元格高度的 UITableViewCell 内的 UITableView

ios - Spotify API 弃用功能别无选择

javascript - 为什么即使使用 obj.focus(),iPhone 上也不会显示键盘?

ios - PFLogInViewController 错误 - 使用 Parse 注销后无法登录 Facebook

iphone - Xcode 3.2.1 - 为什么核心数据生成的类会导致构建错误?

swift - 避免过度!在 Swift 函数中使用 (cellForRowAtIndexPath)

ios - 我想将 Table View 精确放置到导航栏