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

Commit 85e3022

Browse files
author
Rui Peres
committed
We should nil out super first *always*
1 parent 487135c commit 85e3022

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

AsyncDisplayKit/ASTableView.mm

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -288,13 +288,16 @@ - (void)setAsyncDataSource:(id<ASTableViewDataSource>)asyncDataSource
288288
// the (common) case of nilling the asyncDataSource in the ViewController's dealloc. In this case our _asyncDataSource
289289
// will return as nil (ARC magic) even though the _proxyDataSource still exists. It's really important to nil out
290290
// _proxyDataSource.target in this case because calls to _ASTableViewProxy will start failing and cause crashes.
291+
292+
super.dataSource = nil;
291293

292294
if (asyncDataSource == nil) {
293-
_proxyDataSource.target = nil;
294295
_asyncDataSource = nil;
296+
_proxyDataSource = nil;
295297
} else {
296-
_proxyDataSource.target = asyncDataSource;
297298
_asyncDataSource = asyncDataSource;
299+
_proxyDataSource = [[_ASTableViewProxy alloc] initWithTarget:_asyncDataSource interceptor:self];
300+
super.dataSource = (id<UITableViewDataSource>)_proxyDataSource;
298301
}
299302
}
300303

@@ -305,15 +308,16 @@ - (void)setAsyncDelegate:(id<ASTableViewDelegate>)asyncDelegate
305308
// will return as nil (ARC magic) even though the _proxyDelegate still exists. It's really important to nil out
306309
// _proxyDelegate.target in this case because calls to _ASTableViewProxy will start failing and cause crashes.
307310

311+
super.delegate = nil;
312+
308313
if (asyncDelegate == nil) {
309314
// order is important here, the delegate must be callable while nilling super.delegate to avoid random crashes
310315
// in UIScrollViewAccessibility.
311-
super.delegate = nil;
312316
_asyncDelegate = nil;
313-
_proxyDelegate = nil;
317+
_proxyDelegate = nil;
314318
} else {
315-
_proxyDelegate = [[_ASTableViewProxy alloc] initWithTarget:asyncDelegate interceptor:self];;
316319
_asyncDelegate = asyncDelegate;
320+
_proxyDelegate = [[_ASTableViewProxy alloc] initWithTarget:asyncDelegate interceptor:self];
317321
super.delegate = (id<UITableViewDelegate>)_proxyDelegate;
318322
}
319323
}

0 commit comments

Comments
 (0)