mokagio / UICollectionViewLeftAlignedLayout

A layout for UICollectionView that aligns the cells to the left.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

EXC_BAD_ACCESS

esetnik opened this issue · comments

I am getting a crash when using UICollectionViewLeftAlignedLayout on line 47. This only occurs if I set estimatedItemSize to use dynamic sizing.

NSArray *originalAttributes = [super layoutAttributesForElementsInRect:rect];

Hello @esetnik, thanks for the report. I shall look into it, but cannot guarantee it is going to be soon... If you find a solution please feel free to submit a PR

I also filed a radar with Apple. I think this is an iOS bug because I get a
similar crash when using the superclass flow layout.
On Sun, Jan 3, 2016 at 2:53 AM Giovanni Lodi notifications@github.com
wrote:

Hello @esetnik https://github.com/esetnik, thanks for the report. I
shall look into it, but cannot guarantee it is going to be soon... If you
find a solution please feel free to submit a PR


Reply to this email directly or view it on GitHub
#9 (comment)
.

@esetnik Hello! Is any update for this circumstance?
If I don't copy attribute, it would not cause EXC_BAD_ACCESS.
But xcode will told me warning said "UICollectionViewFlowLayout has cached frame mismatch".

Thanks for your help!!

UICollectionViewLayoutAttributes* currentItemAttributes = [super layoutAttributesForItemAtIndexPath:indexPath]; delete copy fix this

I get the same "loop" that leads to the EXC_BAD_ACCESS bug on iOS 9.3 but not on iOS 10+

If I comment out this overwritten method in UICollectionViewLeftAlignedLayout.m then it works on iOS 9 (layout is left aligned) but the layout is not left aligned on iOS 10.

- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
{
    NSArray *originalAttributes = [super layoutAttributesForElementsInRect:rect];
    NSMutableArray *updatedAttributes = [NSMutableArray arrayWithArray:originalAttributes];
    for (UICollectionViewLayoutAttributes *attributes in originalAttributes)
    {
        if (!attributes.representedElementKind)
        {
            NSUInteger index = [updatedAttributes indexOfObject:attributes];
            updatedAttributes[index] = [self layoutAttributesForItemAtIndexPath:attributes.indexPath];
        }
    }

    return updatedAttributes;
}

Anyone found a way around this for iOS 9?
Anyone knows how to at compile time exclude code based on iOS version?

screen shot 2017-01-03 at 10 07 00

Thanks GMCoder.

Reproduce:

IOS 9,
set estimatedItemSize property

iOS 9,
According to this issue, it seems that an infinite loop occurs only when estimatedItemSize is larger than final itemSize.
I set estimatedItemSize to CGSizeMake(1,1) to avoid crash.
(Updated)
Adding support for cell sizing is another solution