3
votes

I use UICollectionView with default UICollectionViewFlowLayout. It works on iOS 8, but on iOS 7.1 I get

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Auto Layout still required after executing -layoutSubviews. UICollectionView's implementation of -layoutSubviews needs to call super

I found this “Auto Layout still required after executing -layoutSubviews” with UITableViewCell subclass but none of the solution works

Another clue is that I add some views into the UICollectionView, and setup AutoLayout for that view

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.collectionView addSubview:button];

    [button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.equalTo(self.collectionView);
        make.height.mas_equalTo(30);
    }];

This is what in my custom UICollectionView

@implementation FTGCollectionView

- (void)layoutSubviews {
    [super layoutSubviews];
    //[self layoutIfNeeded]; // Should not call as it cause collection view to not scroll
}

@end
1
have you override layoutSubviews? if so, have you called super.layoutSubviews? if not then here you are :)Julian
I see that this can happen to UICollectionView, UITextField, UITableView, UINavigationBar, ... My workaround is to disable autoLayout for subviews (and grand children subviews) and set frame manuallyonmyway133
For UICollectionView, we can add subview into UICollectionReusableView in its layoutSubviewsonmyway133

1 Answers

1
votes

I think it is an iOS 7 bug, instead of [self.collectionView addSubview:button]; I change to [self.view addSubview:button];, self.view is self.collectionView's parent view.

So in iOS7 don't add subview to UICollectionView and use auto-layout for that subview