So I have a button that looks like a pencil in a collection view cell xib.
Then I have this code.
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "groupsCollectionViewCellIdentifier", for: indexPath) as! GroupCollectionViewCell
//add action to the edit button
cell.editButton.tag = indexPath.row
cell.editButton.addTarget(self, action: #selector(GroupsCollectionViewController.editGroupAction), for: .touchUpInside)
return cell
}
//segue to edit group
func editGroupAction() {
performSegue(withIdentifier: "editGroupSegue", sender: self)
}
But whenever I click the edit button. Nothing is happening. I wonder what's missing.
Go to the Storyboard and drag a Right Bar Button Item to right side of the Navigation Bar of the Collection View Controller. Select the Bar Button Item and go to the Attributes inspector. Change the Custom Item Value to Add in the Bar Button Item section.
A collection view delegate manages user interactions with the collection view's contents, including item selection, highlighting, and performing actions on those items. The methods of this protocol are all optional. When configuring the collection view object, assign your delegate object to its delegate property.
I realize this ticket is pretty old, but I had the same problem, and found a different solution.
I ran Xcode with the view-debugger. While the button was sized correctly, it's superview had a width of 0 points. This would make it impossible to tap on this button, or any other subviews.
Just mentioning this, as it might be worth trying out.
Try this one on your cell
cell.contentView.isUserInteractionEnabled = false
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