I am attempting to place a UIButton in a UICollectionView supplementary view (footer). I have connected the UIButton using storyboards to a subclass of UICollectionViewCell and can change it's properties programmatically including the background image. However, when I wire up the touch up inside event of the button to a method, it does not fire. In fact, the button does not even appear to be responding visually to the user's touch. In troubleshooting, I attempted to add a UIButton to the collection view's header and see identical behavior. Adding the button to an unrelated view produces interaction effects when pressed.
Is there something special I need to do to implement a UIButton in a UICollection supplementary view?
A supplementary view should be a
UICollectionReusableView
(or subclass thereof), not aUICollectionViewCell
.Anyway, if the button's not responding, the first thing to do is check that all of its ancestor views have
userInteractionEnabled
set toYES
. Pause in the debugger once the button is on screen and do this:Find the button in the list and copy its address. Then you can check it and each superview. Example:
Here I found that all views up to the root (the
UIWindow
) returnYES
fromisUserInteractionEnabled
. The window's superview is nil.I have a custom button which subclasses
UIControl
and put it inside aUICollectionReusableView
. To make it work, I made every single subview of the control and its subviews' subviews handle no user interaction.Since adding that code, all event listeners to
.TouchUpInside
would fire, and the control will visually highlight when pressed down.