Good day to all, I have a weird problem with tapping on a button inside collection view cell when search results controllers is active.
So, I'm initializing searchController like this:
private let searchController = UISearchController(searchResultsController: nil)
In my viewDidLoad()
:
searchController.searchResultsUpdater = self
searchController.obscuresBackgroundDuringPresentation = false
searchController.definesPresentationContext = true
navigationItem.searchController = searchController
Making data source:
private func makeDataSource() -> DataSource {
let cellRegistration = UICollectionView.CellRegistration(
handler: CellProvider().cellRegistrationHandler
)
return DataSource(collectionView: collectionView) {
(collectionView: UICollectionView,
indexPath: IndexPath,
item: IngredientViewData) in
return collectionView.dequeueConfiguredReusableCell(
using: cellRegistration,
for: indexPath,
item: item
)
}
}
Nothing fancy.
In the CellProvider
:
var buttonConfiguration = addButtonConfiguration(for: item)
buttonConfiguration.tintColor = .systemBlue
cell.accessories = [
.customView(configuration: buttonConfiguration),
.disclosureIndicator(displayed: .always)
]
cell.contentConfiguration = contentConfiguration
private func addButtonConfiguration(for item: IngredientViewData) -> UICellAccessory.CustomViewConfiguration
{
let symbolName = item.isSelected ? "checkmark.circle" : "circle"
let symbolConfiguration = UIImage.SymbolConfiguration(textStyle: .title1)
let image = UIImage(
systemName: symbolName,
withConfiguration: symbolConfiguration
)
let button = AddButton()
button.addTarget(
nil,
action: #selector(IngredientsCollectionViewController.didPressDoneButton),
for: .touchUpInside
)
button.id = item.id
button.setImage(image, for: .normal)
return UICellAccessory.CustomViewConfiguration(
customView: button, placement: .leading(displayed: .always))
}
Pretty basic setup. Simple button and selector to the view controller.
Tapping works fine when searchController is not active. And if it is, then IngredientsCollectionViewController.didPressDoneButton
won't be called.
What am I missing?