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)
}
*
What am I doing wrong?
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let movie : Movie
movie = MOVIE_ARRAY[indexPath.row]
print(movie.plot)
}
You have added a TapGestureRecognizer
on the view. TapGestureRecognizer has a property cancelsTouchesInView
.
- var cancelsTouchesInView: Bool { get set }
A Boolean value affecting whether touches are delivered to a view when a gesture is recognized.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With