I have a view with a collectionView and it shows me several cells. Each cell has several buttons. In one of the cell buttons when pressed, I want to present another view as a 'popover'.
I can not show the view, if I do it through the storyboard with a segue and prepareforsegue the compiler just tells me that I need an anchor that is fixed. As the button is not fixed (because it depends on each cell?), I change the anchor to the view that the collection has but it does not work because the view always comes out in the same place (top left corner)
I have tried to implement it by means of code within the function: func collectionView (_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath)
and add an addTarget to the cell button so that when you press it call the function that shows view but it does not work.
@objc func pressButton(button: UIButton) {
self.popoverViewController = self.storyboard?.instantiateViewController(withIdentifier: "ChildInfo") as! MyViewController
self.popoverViewController.modalPresentationStyle = UIModalPresentationStyle.popover
self.popoverViewController.popoverPresentationController!.delegate = self
self.present(self.popoverViewController, animated: true, completion: nil )
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let cell = collectionView.cellForItem(at: indexPath) as! MyCell
cell.indexPath = indexPath.row
cell.pruebaButton.addTarget(self, action: #selector(pressButton(button:)), for: .touchDown)
}