Remove the nil-asyncDelegate proxy.

Fixes #349.
This commit is contained in:
Nadine Salter
2015-03-11 17:43:45 -07:00
parent ac9337a629
commit a79b771a85
4 changed files with 25 additions and 15 deletions

View File

@@ -28,7 +28,7 @@
@interface ASCollectionView : UICollectionView @interface ASCollectionView : UICollectionView
@property (nonatomic, weak) id<ASCollectionViewDataSource> asyncDataSource; @property (nonatomic, weak) id<ASCollectionViewDataSource> asyncDataSource;
@property (nonatomic, weak) id<ASCollectionViewDelegate> asyncDelegate; @property (nonatomic, weak) id<ASCollectionViewDelegate> asyncDelegate; // must not be nil
/** /**
* Tuning parameters for a range. * Tuning parameters for a range.

View File

@@ -66,7 +66,8 @@ static BOOL _isInterceptedSelector(SEL sel)
if (!self) { if (!self) {
return nil; return nil;
} }
ASDisplayNodeAssert(target, @"target must not be nil");
ASDisplayNodeAssert(interceptor, @"interceptor must not be nil"); ASDisplayNodeAssert(interceptor, @"interceptor must not be nil");
_target = target; _target = target;
@@ -147,9 +148,6 @@ static BOOL _isInterceptedSelector(SEL sel)
_leadingScreensForBatching = 1.0; _leadingScreensForBatching = 1.0;
_proxyDelegate = [[_ASCollectionViewProxy alloc] initWithTarget:nil interceptor:self];
super.delegate = (id<UICollectionViewDelegate>)_proxyDelegate;
_asyncDataFetchingEnabled = asyncDataFetchingEnabled; _asyncDataFetchingEnabled = asyncDataFetchingEnabled;
_asyncDataSourceLocked = NO; _asyncDataSourceLocked = NO;
@@ -166,6 +164,7 @@ static BOOL _isInterceptedSelector(SEL sel)
- (void)reloadData - (void)reloadData
{ {
ASDisplayNodeAssert(self.asyncDelegate, @"ASCollectionView's asyncDelegate property must be set.");
ASDisplayNodePerformBlockOnMainThread(^{ ASDisplayNodePerformBlockOnMainThread(^{
[super reloadData]; [super reloadData];
}); });
@@ -204,9 +203,15 @@ static BOOL _isInterceptedSelector(SEL sel)
if (_asyncDelegate == asyncDelegate) if (_asyncDelegate == asyncDelegate)
return; return;
_asyncDelegate = asyncDelegate; if (asyncDelegate == nil) {
_proxyDelegate = [[_ASCollectionViewProxy alloc] initWithTarget:_asyncDelegate interceptor:self]; _asyncDelegate = nil;
super.delegate = (id<UICollectionViewDelegate>)_proxyDelegate; _proxyDelegate = nil;
super.delegate = nil;
} else {
_asyncDelegate = asyncDelegate;
_proxyDelegate = [[_ASCollectionViewProxy alloc] initWithTarget:_asyncDelegate interceptor:self];
super.delegate = (id<UICollectionViewDelegate>)_proxyDelegate;
}
} }
- (void)setTuningParameters:(ASRangeTuningParameters)tuningParameters forRangeType:(ASLayoutRangeType)rangeType - (void)setTuningParameters:(ASRangeTuningParameters)tuningParameters forRangeType:(ASLayoutRangeType)rangeType

View File

@@ -28,7 +28,7 @@
@interface ASTableView : UITableView @interface ASTableView : UITableView
@property (nonatomic, weak) id<ASTableViewDataSource> asyncDataSource; @property (nonatomic, weak) id<ASTableViewDataSource> asyncDataSource;
@property (nonatomic, weak) id<ASTableViewDelegate> asyncDelegate; @property (nonatomic, weak) id<ASTableViewDelegate> asyncDelegate; // must not be nil
/** /**
* Tuning parameters for a range. * Tuning parameters for a range.

View File

@@ -66,6 +66,7 @@ static BOOL _isInterceptedSelector(SEL sel)
return nil; return nil;
} }
ASDisplayNodeAssert(target, @"target must not be nil");
ASDisplayNodeAssert(interceptor, @"interceptor must not be nil"); ASDisplayNodeAssert(interceptor, @"interceptor must not be nil");
_target = target; _target = target;
@@ -149,9 +150,6 @@ static BOOL _isInterceptedSelector(SEL sel)
_dataController.dataSource = self; _dataController.dataSource = self;
_dataController.delegate = _rangeController; _dataController.delegate = _rangeController;
_proxyDelegate = [[_ASTableViewProxy alloc] initWithTarget:nil interceptor:self];
super.delegate = (id<UITableViewDelegate>)_proxyDelegate;
_asyncDataFetchingEnabled = asyncDataFetchingEnabled; _asyncDataFetchingEnabled = asyncDataFetchingEnabled;
_asyncDataSourceLocked = NO; _asyncDataSourceLocked = NO;
@@ -196,13 +194,20 @@ static BOOL _isInterceptedSelector(SEL sel)
if (_asyncDelegate == asyncDelegate) if (_asyncDelegate == asyncDelegate)
return; return;
_asyncDelegate = asyncDelegate; if (asyncDelegate == nil) {
_proxyDelegate = [[_ASTableViewProxy alloc] initWithTarget:asyncDelegate interceptor:self]; _asyncDelegate = nil;
super.delegate = (id<UITableViewDelegate>)_proxyDelegate; _proxyDelegate = nil;
super.delegate = nil;
} else {
_asyncDelegate = asyncDelegate;
_proxyDelegate = [[_ASTableViewProxy alloc] initWithTarget:asyncDelegate interceptor:self];
super.delegate = (id<UITableViewDelegate>)_proxyDelegate;
}
} }
- (void)reloadData - (void)reloadData
{ {
ASDisplayNodeAssert(self.asyncDelegate, @"ASTableView's asyncDelegate property must be set.");
ASDisplayNodePerformBlockOnMainThread(^{ ASDisplayNodePerformBlockOnMainThread(^{
[super reloadData]; [super reloadData];
}); });