I have a view controller with only one element inside - UICollectionView. This UIViewController is embedded in UINavigationController. In viewDidLoad method of this ViewController, I am initialising UISearchController and adding it to NavigationController. The problem is that whenever I try to search for something and I am currently entering the text in search bar, I need to tap 2 times on the UICollectionViewCell in order to trigger the tap. It looks like UISearchController is blocking the tap gesture of UICollectionViewCell. When I tap for the first time, the only thing that is happening is that "Cancel" button of the search bar is hiding. And then I need to tap another time to actually trigger the tap. I have tried many things to fix that, because I don't want the user having to tap 2 times on the cell instead of 1. These are the methods that I am calling in viewDidLoad method of this ViewController:
UISearchController initialisation:
searchController.searchResultsUpdater = self
navigationItem.hidesSearchBarWhenScrolling = false
navigationItem.searchController = searchController
definesPresentationContext = true
UICollectionView initialisation:
self.collectionView?.delegate = self
self.collectionView?.register(MyCell.self, forCellWithReuseIdentifier: MyCell.identifier)
self.collectionView?.contentInset = UIEdgeInsets(top: collectionViewVerticalInset, left: collectionViewHorizontalInset, bottom: collectionViewVerticalInset, right: collectionViewHorizontalInset)
UICollectionView layout initialisation:
let layout = UICollectionViewFlowLayout()
self.collectionView?.collectionViewLayout = layout
guard let collectionView = collectionView else { return }
UICollectionView data source initialisation:
dataSource = UICollectionViewDiffableDataSource<Section, MyEntity>(collectionView: collectionView) { (collectionView, indexPath, myEntity) -> UICollectionViewCell in
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MyCell, for: indexPath) as! MyCell
cell.setupCell(myEntity: MyEntity)
return cell
}
I didn't changed anything in UICollectionView inside the storyboard. Also this ViewController is presented modally.