diff --git a/AsyncDisplayKit/ASCollectionView.h b/AsyncDisplayKit/ASCollectionView.h index 71fbb39bf1..b99f55a7da 100644 --- a/AsyncDisplayKit/ASCollectionView.h +++ b/AsyncDisplayKit/ASCollectionView.h @@ -28,7 +28,7 @@ @interface ASCollectionView : UICollectionView @property (nonatomic, weak) id asyncDataSource; -@property (nonatomic, weak) id asyncDelegate; +@property (nonatomic, weak) id asyncDelegate; // must not be nil /** * Tuning parameters for a range. diff --git a/AsyncDisplayKit/ASCollectionView.mm b/AsyncDisplayKit/ASCollectionView.mm index e02c392bca..80786df40d 100644 --- a/AsyncDisplayKit/ASCollectionView.mm +++ b/AsyncDisplayKit/ASCollectionView.mm @@ -66,7 +66,8 @@ static BOOL _isInterceptedSelector(SEL sel) if (!self) { return nil; } - + + ASDisplayNodeAssert(target, @"target must not be nil"); ASDisplayNodeAssert(interceptor, @"interceptor must not be nil"); _target = target; @@ -147,9 +148,6 @@ static BOOL _isInterceptedSelector(SEL sel) _leadingScreensForBatching = 1.0; - _proxyDelegate = [[_ASCollectionViewProxy alloc] initWithTarget:nil interceptor:self]; - super.delegate = (id)_proxyDelegate; - _asyncDataFetchingEnabled = asyncDataFetchingEnabled; _asyncDataSourceLocked = NO; @@ -166,6 +164,7 @@ static BOOL _isInterceptedSelector(SEL sel) - (void)reloadData { + ASDisplayNodeAssert(self.asyncDelegate, @"ASCollectionView's asyncDelegate property must be set."); ASDisplayNodePerformBlockOnMainThread(^{ [super reloadData]; }); @@ -204,9 +203,15 @@ static BOOL _isInterceptedSelector(SEL sel) 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; + } } - (void)setTuningParameters:(ASRangeTuningParameters)tuningParameters forRangeType:(ASLayoutRangeType)rangeType diff --git a/AsyncDisplayKit/ASTableView.h b/AsyncDisplayKit/ASTableView.h index b5f60c3070..f783a5e880 100644 --- a/AsyncDisplayKit/ASTableView.h +++ b/AsyncDisplayKit/ASTableView.h @@ -28,7 +28,7 @@ @interface ASTableView : UITableView @property (nonatomic, weak) id asyncDataSource; -@property (nonatomic, weak) id asyncDelegate; +@property (nonatomic, weak) id asyncDelegate; // must not be nil /** * Tuning parameters for a range. diff --git a/AsyncDisplayKit/ASTableView.mm b/AsyncDisplayKit/ASTableView.mm index 5e7ecf249f..4c2b79ca01 100644 --- a/AsyncDisplayKit/ASTableView.mm +++ b/AsyncDisplayKit/ASTableView.mm @@ -66,6 +66,7 @@ static BOOL _isInterceptedSelector(SEL sel) return nil; } + ASDisplayNodeAssert(target, @"target must not be nil"); ASDisplayNodeAssert(interceptor, @"interceptor must not be nil"); _target = target; @@ -149,9 +150,6 @@ static BOOL _isInterceptedSelector(SEL sel) _dataController.dataSource = self; _dataController.delegate = _rangeController; - _proxyDelegate = [[_ASTableViewProxy alloc] initWithTarget:nil interceptor:self]; - super.delegate = (id)_proxyDelegate; - _asyncDataFetchingEnabled = asyncDataFetchingEnabled; _asyncDataSourceLocked = NO; @@ -196,13 +194,20 @@ 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; + } } - (void)reloadData { + ASDisplayNodeAssert(self.asyncDelegate, @"ASTableView's asyncDelegate property must be set."); ASDisplayNodePerformBlockOnMainThread(^{ [super reloadData]; });