didSelectItemAt没有被调用

didSelectItemAt没有被调用

本文介绍了didSelectItemAt没有被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我准备好要执行收集视图了,我正在尝试执行didSelectItemAt来选择详细视图.但是我只想测试记录每个项目,而不是记录日志.

I have my collection view ready to go and I'm trying to do didSelectItemAt to segue to the detail view. But I just want to test out logging each of the items and it's not logging.

我已经设置了所有代表:

I set all the delegates already:

*

class ViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, UISearchBarDelegate {*

    @IBOutlet weak var activityIndicatorView: UIActivityIndicatorView!
    @IBOutlet weak var searchBar: UISearchBar!
    @IBOutlet weak var collection: UICollectionView!

    override func viewDidLoad() {
        super.viewDidLoad()
        collection.dataSource = self
        collection.delegate = self
        searchBar.delegate = self

        activityIndicatorView.isHidden = true


        let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "dismissKeyboard")
        view.addGestureRecognizer(tap)
    }

*

我在做什么错了?

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
    let movie : Movie

    movie = MOVIE_ARRAY[indexPath.row]
    print(movie.plot)
}

推荐答案

您已在视图上添加了TapGestureRecognizer. TapGestureRecognizer具有属性cancelsTouchesInView.

You have added a TapGestureRecognizer on the view. TapGestureRecognizer has a property cancelsTouchesInView.

一个布尔值,影响在识别手势后是否将触摸传递给视图.

A Boolean value affecting whether touches are delivered to a view when a gesture is recognized.

默认情况下为true,将阻止调用didSelectItemAt,因为在识别出轻击之后,触摸不会传递到视图.您需要像这样将其设置为false:

This is true by default and will prevent calling didSelectItemAt since touches will not be delivered to the view after a tap is recognized.You need to set it to false like this:

let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "dismissKeyboard")
tap.cancelsTouchesInView = false
view.addGestureRecognizer(tap)

这篇关于didSelectItemAt没有被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 07:27