Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 6 beta4, UIButton is not responsable in collectionviewcell

I am using Xcode 6.0 beta 4, I find that the buttons in the UICollectionViewCell is not response to the tap.

Details as:

UICollectionViewController

--- UICollectionViewCell

------ UIButton (UIButton has two autolayout constraints to put the UIButton in vertical center and horizontal center in the Cell )

Now make the cell size is something like: (300, 1000)

Run the app in iPhone Simulator or device with iOS 7.0 or 7.1.x, the button is not touchable, but test in iOS 8.0 simulator it's OK. Also if I change the cell size to (300, 200), the button works.

I think it's a bug in this Xcode beta version, right?

And where I can fire the bug to Apple?

like image 506
ZYiOS Avatar asked Mar 18 '23 22:03

ZYiOS


2 Answers

They have forgotten to set an autoresizingMask for the contentView of a UICollectionViewCell

this fix it

self.contentView.autoresizingMask = UIViewAutoresizingFlexibleHeight |    UIViewAutoresizingFlexibleWidth;
like image 155
Alexey Avatar answered Mar 26 '23 20:03

Alexey


It appears that this is not actually a bug, but an incompatibility issue of targeting iOS 7 devices using Xcode 6. ecotax's post describes this in more detail, but here is the response from Apple DTS:

In iOS 7, cells’ content views sized themselves via autoresizing masks. In iOS 8, this was changed, cells stopped using the autoresizing masks and started sizing the content view in layoutSubviews. If a nib is encoded in iOS 8 and then decode it on iOS 7, you’ll have a content view without an autoresizing mask and no other means by which to size itself. So if you ever change the frame of the cell, the content view won’t follow.

Apps being deploying back to iOS 7 will have to work around this by sizing the content view itself, adding autoresizing masks, or adding constraints.

Alexey's solution above will do the trick though:

- (void)awakeFromNib
{
   // Fix for iOS 7 devices targeted using Xcode 6.
   self.contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
}
like image 27
Dalmazio Avatar answered Mar 26 '23 19:03

Dalmazio