From 479d40464e78c6ac1b39406b2bf6059238b8ba85 Mon Sep 17 00:00:00 2001 From: Max Wang Date: Fri, 9 Feb 2018 12:16:18 -0800 Subject: [PATCH] [ASTableNode & ASCollectionNode] Keepalive reference for node if their view is necessarily alive (has a superview). (#793) * fix SIMULATE_WEB_RESPONSE not imported #449 * Fix to make rangeMode update in right time * Keep collection/table node alive if view still in use. --- Source/ASCollectionNode.mm | 7 +++++++ Source/ASCollectionView.mm | 21 ++++++++++++++++++++- Source/ASTableNode.mm | 7 +++++++ Source/ASTableView.mm | 21 ++++++++++++++++++++- Tests/ASCollectionViewTests.mm | 1 + 5 files changed, 55 insertions(+), 2 deletions(-) diff --git a/Source/ASCollectionNode.mm b/Source/ASCollectionNode.mm index 2449377fd..01669ca79 100644 --- a/Source/ASCollectionNode.mm +++ b/Source/ASCollectionNode.mm @@ -172,6 +172,13 @@ - (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionVi return self; } +- (void)dealloc +{ + if ([self isNodeLoaded]) { + ASDisplayNodeAssert(self.view.superview == nil, @"Node's view should be removed from hierarchy."); + } +} + #pragma mark ASDisplayNode - (void)didLoad diff --git a/Source/ASCollectionView.mm b/Source/ASCollectionView.mm index 05ed5ebf9..10dd6dc9a 100644 --- a/Source/ASCollectionView.mm +++ b/Source/ASCollectionView.mm @@ -151,7 +151,12 @@ @interface ASCollectionView ()