tableview visibleCells 导致崩溃
tableview visibleCells causes crash
override func viewDidDisappear(_ animated: Bool) {
tableView.visibleCells.forEach {
if let cell = [=10=] as? PostsWithVideoCustom , let player = cell.player {
player.pause()
cell.player = nil
}
}
}
我在viewDidDisappear
上使用这个代码,正常。
但是,如果我 performSegue
在 viewWillAppear
override func viewWillAppear(_ animated: Bool) {
if userDefaults.string(forKey: "goToEvent") != nil {
performSegue(withIdentifier: "postToEvent", sender: self)
}
}
我在线上遇到崩溃 tableView.visibleCells.forEach
如何处理此崩溃以及可能导致崩溃的原因?
更新
只有当应用程序在被杀死后启动时才会发生此崩溃,当从后台唤醒时不会发生
崩溃
Crashed: com.apple.main-thread
0 APP 0x104521cd4 specialized Posts.viewDidDisappear(_:) (Posts.swift:2127)
1 APP 0x104519864 @objc Posts.viewWillAppear(_:) + 4334082148
2 UIKitCore 0x247561684 -[UIViewController _setViewAppearState:isAnimating:] + 488
3 UIKitCore 0x247562008 -[UIViewController __viewDidDisappear:] + 144
4 UIKitCore 0x2474c31d8 -[UINavigationController viewDidDisappear:] + 232
5 UIKit 0x23b4b5ea8 -[UINavigationControllerAccessibility viewDidDisappear:] + 40
6 UIKitCore 0x247561684 -[UIViewController _setViewAppearState:isAnimating:] + 488
7 UIKitCore 0x247562008 -[UIViewController __viewDidDisappear:] + 144
8 UIKitCore 0x247498890 -[UITabBarController viewDidDisappear:] + 100
9 UIKitCore 0x247561684 -[UIViewController _setViewAppearState:isAnimating:] + 488
10 UIKitCore 0x247562008 -[UIViewController __viewDidDisappear:] + 144
11 UIKitCore 0x247564168 __64-[UIViewController viewDidMoveToWindow:shouldAppearOrDisappear:]_block_invoke.1383 + 44
12 UIKitCore 0x247562764 -[UIViewController _executeAfterAppearanceBlock] + 88
13 UIKitCore 0x247b10ef8 _runAfterCACommitDeferredBlocks + 564
14 UIKitCore 0x247aff93c _cleanUpAfterCAFlushAndRunDeferredBlocks + 352
15 UIKitCore 0x247b1e5a8 __34-[UIApplication _firstCommitBlock]_block_invoke_2 + 136
16 CoreFoundation 0x21b29ee68 __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 20
17 CoreFoundation 0x21b29e76c __CFRunLoopDoBlocks + 272
18 CoreFoundation 0x21b2997d0 __CFRunLoopRun + 1024
19 CoreFoundation 0x21b2990b0 CFRunLoopRunSpecific + 436
20 GraphicsServices 0x21d49979c GSEventRunModal + 104
21 UIKitCore 0x247b05978 UIApplicationMain + 212
22 APP 0x1044f8504 main (InboxInterests.swift:22)
23 libdyld.dylib 0x21ad5e8e0 start + 4
我通过添加
解决了这个问题
if tableView != nil {
}
修复非常简单。但我认为 iOS 首先应该自己管理它。
override func viewDidDisappear(_ animated: Bool) {
tableView.visibleCells.forEach {
if let cell = [=10=] as? PostsWithVideoCustom , let player = cell.player {
player.pause()
cell.player = nil
}
}
}
我在viewDidDisappear
上使用这个代码,正常。
但是,如果我 performSegue
在 viewWillAppear
override func viewWillAppear(_ animated: Bool) {
if userDefaults.string(forKey: "goToEvent") != nil {
performSegue(withIdentifier: "postToEvent", sender: self)
}
}
我在线上遇到崩溃 tableView.visibleCells.forEach
如何处理此崩溃以及可能导致崩溃的原因?
更新
只有当应用程序在被杀死后启动时才会发生此崩溃,当从后台唤醒时不会发生
崩溃
Crashed: com.apple.main-thread
0 APP 0x104521cd4 specialized Posts.viewDidDisappear(_:) (Posts.swift:2127)
1 APP 0x104519864 @objc Posts.viewWillAppear(_:) + 4334082148
2 UIKitCore 0x247561684 -[UIViewController _setViewAppearState:isAnimating:] + 488
3 UIKitCore 0x247562008 -[UIViewController __viewDidDisappear:] + 144
4 UIKitCore 0x2474c31d8 -[UINavigationController viewDidDisappear:] + 232
5 UIKit 0x23b4b5ea8 -[UINavigationControllerAccessibility viewDidDisappear:] + 40
6 UIKitCore 0x247561684 -[UIViewController _setViewAppearState:isAnimating:] + 488
7 UIKitCore 0x247562008 -[UIViewController __viewDidDisappear:] + 144
8 UIKitCore 0x247498890 -[UITabBarController viewDidDisappear:] + 100
9 UIKitCore 0x247561684 -[UIViewController _setViewAppearState:isAnimating:] + 488
10 UIKitCore 0x247562008 -[UIViewController __viewDidDisappear:] + 144
11 UIKitCore 0x247564168 __64-[UIViewController viewDidMoveToWindow:shouldAppearOrDisappear:]_block_invoke.1383 + 44
12 UIKitCore 0x247562764 -[UIViewController _executeAfterAppearanceBlock] + 88
13 UIKitCore 0x247b10ef8 _runAfterCACommitDeferredBlocks + 564
14 UIKitCore 0x247aff93c _cleanUpAfterCAFlushAndRunDeferredBlocks + 352
15 UIKitCore 0x247b1e5a8 __34-[UIApplication _firstCommitBlock]_block_invoke_2 + 136
16 CoreFoundation 0x21b29ee68 __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 20
17 CoreFoundation 0x21b29e76c __CFRunLoopDoBlocks + 272
18 CoreFoundation 0x21b2997d0 __CFRunLoopRun + 1024
19 CoreFoundation 0x21b2990b0 CFRunLoopRunSpecific + 436
20 GraphicsServices 0x21d49979c GSEventRunModal + 104
21 UIKitCore 0x247b05978 UIApplicationMain + 212
22 APP 0x1044f8504 main (InboxInterests.swift:22)
23 libdyld.dylib 0x21ad5e8e0 start + 4
我通过添加
解决了这个问题if tableView != nil {
}
修复非常简单。但我认为 iOS 首先应该自己管理它。