Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting button action : UICollectionView Cell

Tags:

I have created a UICollectionViewCell by nib and added a button inside it and created a .h and .m files added the class to the nibs file's owner.then wrote a button action in the .m connected it via outlet.

The collection view is populating fine ,but cannot get the buton action triggered. I think the delegate for collection cell is called.

How can i get the button action?

like image 390
Lithu T.V Avatar asked Dec 07 '12 06:12

Lithu T.V


1 Answers

I had this problem as well. No subviews would receive touch events. While Scott K's workaround does work, I still felt something was wrong. So I took another look at my nib, and noticed that the original subview I used to create a UICollectionViewCell was a UIView. Even though I changed the class to a subclass of UICollectionViewCell, XCode still considered it a UIView, and hence the issues you see with contentView not catching touch events.

To fix this, I redid the nib by making sure to drag a UICollectionViewCell object, and moving all the subviews to that. Afterwards, touch events began to work on my cell's subviews.

Could indicator to see if your nib is configured as a UICollectionViewCell is look at the icon for your high level view.

enter image description here

If it doesn't look like this, then its probably going to interpret touch events wrong.

like image 114
haider Avatar answered Sep 24 '22 15:09

haider