Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit 34b982a

Browse files
author
Rui Peres
committed
Fix regression on the nil delegate #706
1 parent ca5780f commit 34b982a

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

AsyncDisplayKit/ASCollectionView.mm

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,12 @@ - (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionVi
202202
// and should not trigger a relayout.
203203
_ignoreMaxSizeChange = CGSizeEqualToSize(_maxSizeForNodesConstrainedSize, CGSizeZero);
204204

205+
_proxyDelegate = [[_ASCollectionViewProxy alloc] initWithTarget:[NSNull null] interceptor:self];
206+
super.delegate = (id<UICollectionViewDelegate>)_proxyDelegate;
207+
208+
_proxyDataSource = [[_ASCollectionViewProxy alloc] initWithTarget:[NSNull null] interceptor:self];
209+
super.dataSource = (id<UICollectionViewDataSource>)_proxyDataSource;
210+
205211
self.backgroundColor = [UIColor whiteColor];
206212

207213
[self registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"_ASCollectionViewCell"];
@@ -253,10 +259,10 @@ - (void)setAsyncDataSource:(id<ASCollectionViewDataSource>)asyncDataSource
253259
// the (common) case of nilling the asyncDataSource in the ViewController's dealloc. In this case our _asyncDataSource
254260
// will return as nil (ARC magic) even though the _proxyDataSource still exists. It's really important to nil out
255261
// super.dataSource in this case because calls to _ASTableViewProxy will start failing and cause crashes.
262+
_asyncDataSource = nil;
256263

257264
if (asyncDataSource == nil) {
258265
super.dataSource = nil;
259-
_asyncDataSource = nil;
260266
_proxyDataSource = nil;
261267
_asyncDataSourceImplementsConstrainedSizeForNode = NO;
262268
} else {
@@ -278,10 +284,11 @@ - (void)setAsyncDelegate:(id<ASCollectionViewDelegate>)asyncDelegate
278284
// will return as nil (ARC magic) even though the _proxyDelegate still exists. It's really important to nil out
279285
// super.delegate in this case because calls to _ASTableViewProxy will start failing and cause crashes.
280286

287+
// order is important here, the delegate must be callable while nilling super.delegate to avoid random crashes
288+
// in UIScrollViewAccessibility.
289+
super.delegate = nil;
290+
281291
if (asyncDelegate == nil) {
282-
// order is important here, the delegate must be callable while nilling super.delegate to avoid random crashes
283-
// in UIScrollViewAccessibility.
284-
super.delegate = nil;
285292
_asyncDelegate = nil;
286293
_proxyDelegate = nil;
287294
_asyncDelegateImplementsInsetSection = NO;

AsyncDisplayKit/ASTableView.mm

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,12 @@ - (void)configureWithAsyncDataFetching:(BOOL)asyncDataFetchingEnabled
218218
// If the initial size is 0, expect a size change very soon which is part of the initial configuration
219219
// and should not trigger a relayout.
220220
_ignoreMaxWidthChange = (_maxWidthForNodesConstrainedSize == 0);
221+
222+
_proxyDelegate = [[_ASTableViewProxy alloc] initWithTarget:[NSNull null] interceptor:self];
223+
super.delegate = (id<UITableViewDelegate>)_proxyDelegate;
224+
225+
_proxyDataSource = [[_ASTableViewProxy alloc] initWithTarget:[NSNull null] interceptor:self];
226+
super.dataSource = (id<UITableViewDataSource>)_proxyDataSource;
221227
}
222228

223229
- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style
@@ -279,8 +285,9 @@ - (void)setAsyncDataSource:(id<ASTableViewDataSource>)asyncDataSource
279285
// will return as nil (ARC magic) even though the _proxyDataSource still exists. It's really important to nil out
280286
// super.dataSource in this case because calls to _ASTableViewProxy will start failing and cause crashes.
281287

288+
super.dataSource = nil;
289+
282290
if (asyncDataSource == nil) {
283-
super.dataSource = nil;
284291
_asyncDataSource = nil;
285292
_proxyDataSource = nil;
286293
} else {
@@ -297,12 +304,13 @@ - (void)setAsyncDelegate:(id<ASTableViewDelegate>)asyncDelegate
297304
// will return as nil (ARC magic) even though the _proxyDelegate still exists. It's really important to nil out
298305
// super.delegate in this case because calls to _ASTableViewProxy will start failing and cause crashes.
299306

307+
// order is important here, the delegate must be callable while nilling super.delegate to avoid random crashes
308+
// in UIScrollViewAccessibility.
309+
super.delegate = nil;
310+
300311
if (asyncDelegate == nil) {
301-
// order is important here, the delegate must be callable while nilling super.delegate to avoid random crashes
302-
// in UIScrollViewAccessibility.
303-
super.delegate = nil;
304312
_asyncDelegate = nil;
305-
_proxyDelegate = nil;
313+
_proxyDelegate = nil;
306314
} else {
307315
_asyncDelegate = asyncDelegate;
308316
_proxyDelegate = [[_ASTableViewProxy alloc] initWithTarget:asyncDelegate interceptor:self];

0 commit comments

Comments
 (0)