@@ -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 ;
0 commit comments