我UIViewController
UICollectionView
delegate
,正在实施dataSource
和successBlock
。 95%的一切都运行正常,但有时我会崩溃(下面的日志,代码等)。我认为当myOperation
的{{1}}在控制器被解除分配的同一时刻执行时会发生这种情况(但我不确定)。
考虑other question from SOF我假设myCollectionView == nil
,但delegate
仍然指向某个地方(不应该改变它,它只是分配属性,就我而言)看到)。我不知道如何解决这类问题,有没有人有任何想法?
崩溃日志:
MyCollectionViewController.m line 0
__destroy_helper_block_
Crashed: com.apple.main-thread
EXC_BAD_ACCESS KERN_INVALID_ADDRESS at 0x0000000a
调用堆栈:
libobjc.A.dylib
objc_msgSend + 5
retain
UIKit
-[UICollectionViewController collectionView] + 54
MyAppName
MyCollectionViewController.m line 30
-[MyCollectionViewController dealloc]
MyAppName
MyCollectionViewController.m line 0
__destroy_helper_block_
libsystem_blocks.dylib
_Block_release + 216
MyAppName
MyDownloaderController.m line 0
__destroy_helper_block_75
libsystem_blocks.dylib
_Block_release + 216
MyAppName
MyOperation.m line 0
__destroy_helper_block_19
libsystem_blocks.dylib
_Block_release + 216
MyAppName
MyOperation.m line 0
__destroy_helper_block_112
libsystem_blocks.dylib
_Block_release + 216
UIKit
UIApplicationMain + 1136
MyAppName
main.m line 15
main
MyCollectionViewController中30左右的行:
- (void)dealloc {
if ([self isViewLoaded] && self.collectionView) { // line 30
self.collectionView.delegate = nil;
self.collectionView.dataSource = nil;
self.collectionView = nil;
}
}
我的成功阻拦:
MySuccessHandler successBlock = ^(UIImage *image) {
if (weakCell) {
[weakCell.pageImageView setImage:image];
}
};