Reputation: 10162
override func viewDidDisappear(_ animated: Bool) {
tableView.visibleCells.forEach {
if let cell = $0 as? PostsWithVideoCustom , let player = cell.player {
player.pause()
cell.player = nil
}
}
}
I use this code on viewDidDisappear
and it is ok normally.
However, if I performSegue
on viewWillAppear
override func viewWillAppear(_ animated: Bool) {
if userDefaults.string(forKey: "goToEvent") != nil {
performSegue(withIdentifier: "postToEvent", sender: self)
}
}
I am having crash on line tableView.visibleCells.forEach
How can handle this crash and what may cause it?
UPDATE
This crash only happens if the app started after it gets killed, doesn't happen when waken from background
Crash
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
Upvotes: 1
Views: 655
Reputation: 10162
I solved this issue by just adding
if tableView != nil {
}
It was a very easy fix. But I think iOS should manage it itself in the first place.
Upvotes: 3