簡體   English   中英

UITableView didSelect無法在swift 3.0中運行

[英]UITableView didSelect not working in swift 3.0

當我選擇任何行而不是被選中時,不會被調用。在選擇時它的顏色也會變為藍色。 但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)

}

試試這個,它會解決你的問題

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

嘗試這個,

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

categoryLbl.text = categoryArray[indexPath.row].type
    dataDict.setValue(categoryArray[indexPath.row].type, forKey: "category")
    categoryTable?.isHidden = true

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM