diff --git a/AsyncDisplayKit/ASCollectionView.mm b/AsyncDisplayKit/ASCollectionView.mm index 04200238bf..f62908a061 100644 --- a/AsyncDisplayKit/ASCollectionView.mm +++ b/AsyncDisplayKit/ASCollectionView.mm @@ -193,9 +193,9 @@ static BOOL _isInterceptedSelector(SEL sel) return; if (asyncDataSource == nil) { + super.dataSource = nil; _asyncDataSource = nil; _proxyDataSource = nil; - super.dataSource = nil; } else { _asyncDataSource = asyncDataSource; _proxyDataSource = [[_ASCollectionViewProxy alloc] initWithTarget:_asyncDataSource interceptor:self]; @@ -209,9 +209,11 @@ static BOOL _isInterceptedSelector(SEL sel) return; if (asyncDelegate == nil) { + // order is important here, the delegate must be callable while nilling super.delegate to avoid random crashes + // in UIScrollViewAccessibility. + super.delegate = nil; _asyncDelegate = nil; _proxyDelegate = nil; - super.delegate = nil; } else { _asyncDelegate = asyncDelegate; _proxyDelegate = [[_ASCollectionViewProxy alloc] initWithTarget:_asyncDelegate interceptor:self]; diff --git a/AsyncDisplayKit/ASTableView.mm b/AsyncDisplayKit/ASTableView.mm index ff2410eab0..bc332947ec 100644 --- a/AsyncDisplayKit/ASTableView.mm +++ b/AsyncDisplayKit/ASTableView.mm @@ -179,9 +179,9 @@ static BOOL _isInterceptedSelector(SEL sel) return; if (asyncDataSource == nil) { + super.dataSource = nil; _asyncDataSource = nil; _proxyDataSource = nil; - super.dataSource = nil; } else { _asyncDataSource = asyncDataSource; _proxyDataSource = [[_ASTableViewProxy alloc] initWithTarget:_asyncDataSource interceptor:self]; @@ -195,9 +195,11 @@ static BOOL _isInterceptedSelector(SEL sel) return; if (asyncDelegate == nil) { - _asyncDelegate = nil; - _proxyDelegate = nil; + // order is important here, the delegate must be callable while nilling super.delegate to avoid random crashes + // in UIScrollViewAccessibility. super.delegate = nil; + _asyncDelegate = nil; + _proxyDelegate = nil; } else { _asyncDelegate = asyncDelegate; _proxyDelegate = [[_ASTableViewProxy alloc] initWithTarget:asyncDelegate interceptor:self];