我一直在与下面的堆栈跟踪作斗争。我无法重现这个问题,但我知道它发生在大量用户身上(Crashlytics)。
Crashed: com.apple.main-thread
EXC_BAD_ACCESS KERN_INVALID_ADDRESS at 0x0000000000000010
Thread : Crashed: com.apple.main-thread
0 libobjc.A.dylib 0x0000000194187bd0 objc_msgSend + 16
1 UIKit 0x000000018860639c -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 544
2 UIKit 0x00000001885fafc4 -[UITableView _updateVisibleCellsNow:isRecursive:] + 2360
3 UIKit 0x00000001883f0c60 -[UITableView layoutSubviews] + 172
4 UIKit 0x000000018830d874 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 572
5 QuartzCore 0x0000000187c65d58 -[CALayer layoutSublayers] + 168
6 QuartzCore 0x0000000187c60944 CA::Layer::layout_if_needed(CA::Transaction*) + 320
7 QuartzCore 0x0000000187c607e8 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 32
8 QuartzCore 0x0000000187c5ffe8 CA::Context::commit_transaction(CA::Transaction*) + 276
9 QuartzCore 0x0000000187c5fd6c CA::Transaction::commit() + 436
10 UIKit 0x0000000188304848 _afterCACommitHandler + 156
11 CoreFoundation 0x0000000183b46388 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32
12 CoreFoundation 0x0000000183b43314 __CFRunLoopDoObservers + 360
13 CoreFoundation 0x0000000183b436f4 __CFRunLoopRun + 836
...
这发生在拥有UITableView的UIViewController中。视图控制器也是表视图的数据源和委托。
查看堆栈跟踪,我猜测在执行某些动画或慢速操作时视图控制器将被释放。在尝试了所有内容后,我无法找到可能发生这种情况的配置。
您是否有任何关于为什么在其视图仍然可以动画时可以取消分配VC的建议?
答案 0 :(得分:8)
我注意到此次崩溃恰逢从UITableViewController
切换到UIViewController
+ UITableView
。
据推测,UITableViewController
在取消分配表格视图的委托和数据源时非常小。新代码的情况并非如此。
要解决此问题,我将其设置为- (void)dealloc
中的nil:
- (void)dealloc {
_tableView.dataSource = nil;
_tableView.delegate = nil;
}
他们需要设置为nil的原因是both the UITableView's dataSource and delegate are unsafe_unretained references。