iOS 8 GM does not update constraints on collection views
Asked Answered
Z

4

14

In Xcode 6 Beta 7 and all versions before it, I had a collection view that would update its constraints on its cells when an iPad would rotate between landscape and portrait. Now, it doesn't update at all, and in fact it looks exactly like how I leave it in the XIB, which implies to me that it's not updating at all. It appears that the reusable views I'm using are updating correctly, but the cells certainly are not.

Has anyone else run into this issue yet? Anyone have any ideas for how to get past it?

I'm using the iOS 7.1 simulator.

Zebada answered 9/9, 2014 at 20:52 Comment(3)
This appears to be working fine on the 8GM sim, so it appears the problem is 7.1 only. I'll check the 7.0 sim.Zebada
I'm seeing it on 7.1 device and simulator as well. ios8 simulator works correctlyForepeak
Confirmed, this is not working on iOS 7.1 or 7.0.3 SIMs. It is also failing to work on my iPad Air with iOS 7.1.2.Zebada
Z
28

You need to make a subclass of UICollectionViewCell and make that subclass as the superclass of ALL of your cells.

Example:

@interface MDTCollectionViewCell : UICollectionViewCell
@end

@implementation MDTCollectionViewCell

- (void)setBounds:(CGRect)bounds {
    [super setBounds:bounds];
    self.contentView.frame = bounds;
}

@end
Zebada answered 10/9, 2014 at 14:42 Comment(6)
You can also set the contentView frame on the method cellForItemAtIndexPath before returning the cell if you don't want to subclass the UICollectionViewCellCheetah
@Cheetah Yes, that was actually the original fix that cyphers72 in the Apple Dev Forums suggested, but this solution was cleaner for my use case :)Zebada
Thanks for the solution. I am having exactly the same problem. I am now using XCode 6 Beta 7 temporary.Croner
Thanks for the solution...I had the same problem and was frustrated trying to figure out why this was happening on iOS 7.1 only.Highline
I burned over half a day on this B.S. before I found this question. I didn't realize it was specific to Xcode 6, iOS 7.1 simulator. As of Xcode 6.0.1 (6A317) this is still an issue. Just a note, I came closest to a solution by adding [cell.contentView setFrame:CGRectMake(0.0, 0.0, cell.frame.size.width, cell.frame.size.height)]; to collectionView: cellForItemAtIndexPath: but the problem there was that subviews like buttons weren't laying out correctly and would no longer respond to interaction. Fortunately, Mr. Freitag nailed it. Works beautifully now.Audible
Following up on this, I found that Attila H's response fixed some broken animations for me, so I use that approach instead.Zebada
G
3

Override the custom cell's layoutSubviews as a temporary fix:

override func layoutSubviews() {
    contentView.frame = bounds
    super.layoutSubviews()
}
Gather answered 11/9, 2014 at 15:40 Comment(2)
This worked for me on Xcode 6, using swift... Any ideas what goes wrong when not using this?Jaynajayne
this one actually work for me (I used with CollectionView), when mixed with dispatch_async and called it after reloadData()Phenacite
Z
0

The workaround I have come up with is to use the 8.0 simulator for testing in the sim, and build the deployable using Xcode Beta 7. When I build using Beta 7, the app runs without this issue on devices using iOS 7. However, this does not help anyone that is deploying to the app store, so I apologize if this workaround does not work for your situation.

Zebada answered 9/9, 2014 at 22:7 Comment(0)
P
0

in my UICollectionViewCell class I added

override func layoutSubviews() {
    contentView.frame = bounds
    super.layoutSubviews()
}

and I used this code to refresh

dispatch_async(dispatch_get_main_queue(), { () -> Void in
    // in this case vController is UICollectionView
    self.vController.reloadData()
    self.vController.layoutSubviews()
})
Phenacite answered 28/3, 2015 at 16:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.