From 764650fb94933f45f75ec3a509973e5c08eea8f8 Mon Sep 17 00:00:00 2001 From: Nadine Salter Date: Thu, 4 Dec 2014 16:28:04 -0800 Subject: [PATCH] _ASTableViewProxy & _ASCollectionViewProxy fixes. These weren't correctly handling teardown: nilling the `asyncDelegate` created a new selector-forwarding NSProxy that crashed and burned because there was nowhere to forward to. Nil everything correctly. Tentatively fixes #121. --- AsyncDisplayKit/ASCollectionView.m | 28 ++++++++++++++++++++-------- AsyncDisplayKit/ASTableView.m | 24 ++++++++++++++++++------ 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/AsyncDisplayKit/ASCollectionView.m b/AsyncDisplayKit/ASCollectionView.m index 2ab06ff1..cfba0083 100644 --- a/AsyncDisplayKit/ASCollectionView.m +++ b/AsyncDisplayKit/ASCollectionView.m @@ -139,20 +139,32 @@ static BOOL _isInterceptedSelector(SEL sel) { if (_asyncDataSource == asyncDataSource) return; - - _asyncDataSource = asyncDataSource; - _proxyDataSource = [[_ASCollectionViewProxy alloc] initWithTarget:_asyncDataSource interceptor:self]; - super.dataSource = (id)_proxyDataSource; + + if (asyncDataSource == nil) { + _asyncDataSource = nil; + _proxyDataSource = nil; + super.dataSource = nil; + } else { + _asyncDataSource = asyncDataSource; + _proxyDataSource = [[_ASCollectionViewProxy alloc] initWithTarget:_asyncDataSource interceptor:self]; + super.dataSource = (id)_proxyDataSource; + } } - (void)setAsyncDelegate:(id)asyncDelegate { if (_asyncDelegate == asyncDelegate) return; - - _asyncDelegate = asyncDelegate; - _proxyDelegate = [[_ASCollectionViewProxy alloc] initWithTarget:_asyncDelegate interceptor:self]; - super.delegate = (id)_proxyDelegate; + + if (asyncDelegate == nil) { + _asyncDelegate = nil; + _proxyDelegate = nil; + super.delegate = nil; + } else { + _asyncDelegate = asyncDelegate; + _proxyDelegate = [[_ASCollectionViewProxy alloc] initWithTarget:_asyncDelegate interceptor:self]; + super.delegate = (id)_proxyDelegate; + } } - (ASRangeTuningParameters)rangeTuningParameters diff --git a/AsyncDisplayKit/ASTableView.m b/AsyncDisplayKit/ASTableView.m index ee819acd..22932fae 100644 --- a/AsyncDisplayKit/ASTableView.m +++ b/AsyncDisplayKit/ASTableView.m @@ -149,9 +149,15 @@ static BOOL _isInterceptedSelector(SEL sel) if (_asyncDataSource == asyncDataSource) return; - _asyncDataSource = asyncDataSource; - _proxyDataSource = [[_ASTableViewProxy alloc] initWithTarget:_asyncDataSource interceptor:self]; - super.dataSource = (id)_proxyDataSource; + if (asyncDataSource == nil) { + _asyncDataSource = nil; + _proxyDataSource = nil; + super.dataSource = nil; + } else { + _asyncDataSource = asyncDataSource; + _proxyDataSource = [[_ASTableViewProxy alloc] initWithTarget:_asyncDataSource interceptor:self]; + super.dataSource = (id)_proxyDataSource; + } } - (void)setAsyncDelegate:(id)asyncDelegate @@ -159,9 +165,15 @@ static BOOL _isInterceptedSelector(SEL sel) if (_asyncDelegate == asyncDelegate) return; - _asyncDelegate = asyncDelegate; - _proxyDelegate = [[_ASTableViewProxy alloc] initWithTarget:_asyncDelegate interceptor:self]; - super.delegate = (id)_proxyDelegate; + if (asyncDelegate == nil) { + _asyncDelegate = nil; + _proxyDelegate = nil; + super.delegate = nil; + } else { + _asyncDelegate = asyncDelegate; + _proxyDelegate = [[_ASTableViewProxy alloc] initWithTarget:_asyncDelegate interceptor:self]; + super.delegate = (id)_proxyDelegate; + } } - (ASRangeTuningParameters)rangeTuningParameters