thkeen thkeen - 10 months ago 143
Objective-C Question

Autoresizing issue of UICollectionViewCell contentView's frame in Storyboard prototype cell (Xcode 6, iOS 8 SDK) happens when running on iOS 7 only

Got another serious bug with UITableViewCell in Storyboard. FYI if you also Static Cell on Xcode 6: Static UITableViewCell subviews are resized incorrectly (was off the screen, over the right edge) on Xcode 6.1.1, iOS 8.1 SDK

Update 2:
Paste this code at the beginning of your cellForItem and things should be okay:

/** Xcode 6 on iOS 7 hot fix **/
cell.contentView.frame = cell.bounds;
cell.contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
/** End of Xcode 6 on iOS 7 hot fix **/

Update 1: This problem still exists in the official Xcode 6.0.1 ! The best work around is like what KoCMoHaBTa suggested below by setting the frame in cellForItem of the cell (You have to subclass your cell though). It turned out that this is a incompatibility between iOS 8 SDK and iOS 7 (check ecotax's answer below quoted from Apple).

I'm using Xcode 6 Beta 3, iOS 8 SDK. Build Target iOS 7.0 using Swift. Please refer to my problem step by step with screenshots below.

I have a UICollectionView in Storyboard. 1 Prototype UICollectionViewCell which contains 1 label in the centre (no autoresizing rule). Purple background was to mark a contentView that is generated in runtime by the Cell I guess. That view will be resized properly base on my UICollectionViewLayoutDelegate eventually, but not on iOS 7. Notice that I'm using Xcode 6 and the problem only happens on iOS 7.

When I build the app on iOS 8. Everything is okay.

Note: Purple is the contentView, Blue is my UIButton with rounded corner.

However, on iOS 7, all the subViews inside the Cell suddenly shrink to the frame of (0,0,50,50) and never conforms to my Autoresizing rule anymore.

I assume this is a bug in iOS 8 SDK or Swift or maybe Xcode? I'm stuck with this for 2 days without any hope of resolving it. Your help is appreciated.

Thanks a lot guys!


contentView is broken. It can be also fixed in awakeFromNib

   [super awakeFromNib];

   self.contentView.frame = self.bounds;
   self.contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;