Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash when using 2.3.1 in UICollectionViews or similar #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

timbodeit
Copy link

In certain cases (collection views just being one of them), view initialization takes place within a layoutSubviews call.

-[UIView layoutSubviews] does some evaluation of constraints and seems to keep its own references to them. Therefore it is possible, that constraints of the placeholderView are being used, after we're done with view initialization.

As the placeholderView gets replaced it would previously be deallocated immediately. As NSLayoutConstraints only keep weak references on their items this lead to a dangling pointer on
the firstItem property.

This change asynchronously dispatches a block enclosing the placeholderView. This defers the deallocation of the placeholderView until the end of the current runloop cycle and allows the current layoutSubviews call to go through before.

Based on the suggestion by @fuaiyi

Fixes #29

Might fix other issues regarding the iOS 10 Update.


@sunnyxx Thanks for the English readme and in-code documentation.

Note to other users of the framework: Please keep GitHub communication (issues and comments) for open-source projects in English. English is not my mother tongue either, but using a common language makes collaboration a lot easier.

In certain cases (collection views just being one of them), view
initialization takes place within a `layoutSubviews`  call.

-[UIView layoutSubviews] does some evaluation of constraints and seems
to keep its own references to them. Therefore it is possible, that
constraints of the placeholderView are being used, after we're done
with view initialization.

As the `placeholderView` gets replaced it would previously be
deallocated immediately. As NSLayoutConstraints only keep weak
references on their items this lead to a dangling pointer on
the `firstItem` property.

This change asynchronously dispatches a block enclosing the
`placeholderView`. This defers the deallocation of the `placeholderView`
until the end of the current runloop cycle and allows the current
layoutSubviews call to go through before.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

在2.3.1在UICollectionview中RefuseVIew桥接崩溃
1 participant