nguyenhuy/AsyncMessagesViewController

Assertion failure in -[_ASCollectionViewProxy forwardingTargetForSelector:]

Closed this issue · 5 comments

Hi! Here is the scenario: my first view controller has an ASTableView containing some dummy cells for testing. Clicking either cell will push a new view controller named ChatViewController (which is exactly the ViewController from your example), with the exception that the collectionView scrolls to bottom after all the messages are inserted with success.

dataSource.collectionView(collectionView, insertMessages: messages) { (success) -> () in
            if (success) {
                self.scrollCollectionViewToBottom()
            }
        }

After I click the back button, my app crashes giving this log:
screen shot 2015-11-27 at 17 58 21

If I scroll back to top in the ChatViewController and click the back button, the app will not crash. Is there any solution? Thank you!

@StrauneanuDimitri Thanks for trying out this library and reporting this issue. If you press the back button while the collection view is still scrolling, the view will stop scrolling and try to notify its delegate, which has already been deallocated. Thus, a crash occurs.

Could you try to manually set the collection view's delegate to nil right before the delegate itself is deallocated? In my example, ViewController is a (dummy) ASCollectionViewDelegate, so this piece of code in ViewController.swift should work:

    deinit {
        collectionView.asyncDelegate = nil
    }

P/S: I believe the problem is caused by ASDK itself (facebookarchive/AsyncDisplayKit#721) and should be fixed once facebookarchive/AsyncDisplayKit#790 is landed. Until then, we need to nil a weak reference ourselves :(

Yes, it's working now. Much appreciated for that code. This is a fantastic library!

Really happy to know! I will keep you posted regarding the ASDK issue and its fix.

Thanks, It's helpful!