gpt4 book ai didi

ios - didSelectItemAt 未被调用

转载 作者:IT王子 更新时间:2023-10-29 05:17:59 24 4
gpt4 key购买 nike

我的 Collection View 已准备就绪,我正在尝试执行 didSelectItemAt 以转到详细 View 。但我只想测试记录每个项目,但它没有记录。

我已经设置了所有代表:

*

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

enter image description here

最佳答案

您已经在 View 上添加了一个 TapGestureRecognizer。 TapGestureRecognizer 有一个属性 cancelsTouchesInView

- var cancelsTouchesInView: Bool { get set }

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

默认情况下为 true 并且将阻止调用 didSelectItemAt,因为在识别点击后触摸不会传递到 View 。您需要像这样将其设置为 false:

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

关于ios - didSelectItemAt 未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39780373/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com