iOS:静态TableViewController中的UITapGestureRecognizer。没有调用PrepareForSegue

时间:2016-06-30 10:06:31

标签: ios xcode uitableview uitapgesturerecognizer

我在每个单元格中都有静态TableViewController和PrepareForSegue。在添加包含textField的新单元格之前,我没有问题。为解雇Keyboard,我在viewDidLoad中添加了UITapGestureRecognizer。添加此TapGesture后,Cell中的singleSelection不再工作。有具体原因吗?

  override func viewDidLoad() {
            super.viewDidLoad()

            addressTextField.delegate=self

            let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(TableViewController.dismissKeyboard))
            view.addGestureRecognizer(tap)

    }


      func dismissKeyboard() {
            view.endEditing(true)
        }


     override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
            if segue.identifier == "LinkToRegion" {
                let viewController = segue.destinationViewController as! RegionTableViewController
                viewController.parameter = regionLabel.text
                viewController.delegate=self
            }
            if segue.identifier == "LinkToProv" {
                let viewController = segue.destinationViewController as! ProvTableViewController
                viewController.parameter = provLabel.text
                viewController.delegate=self
            }
            if segue.identifier == "LinkToCity" {
                let viewController = segue.destinationViewController as! CityTableViewController
                viewController.cities = cities
                viewController.parameter = cityLabel.text
                viewController.delegate=self
            }
            if segue.identifier == "LinkToInvia" {
                let viewController = segue.destinationViewController as! InviaViewController
            }
        }

2 个答案:

答案 0 :(得分:0)

通过向UITapGestureRecognizer添加view识别器,视图将拦截触摸事件,您的表格视图单元格将永远不会接收它们。因此,为什么他们永远不会表现出选择。

一种解决方案是仅在文本字段具有焦点时添加点击手势识别器,然后在解雇时将其删除

答案 1 :(得分:0)

我使用故事板解决了问题。在tableView元素上,在键盘下,只需设置:“拖动时关闭”。