gpt4 book ai didi

ios - tableview visibleCells 导致崩溃

转载 作者:搜寻专家 更新时间:2023-11-01 06:25:17 24 4
gpt4 key购买 nike

override func viewDidDisappear(_ animated: Bool) {
tableView.visibleCells.forEach {
if let cell = $0 as? PostsWithVideoCustom , let player = cell.player {
player.pause()
cell.player = nil
}
}
}

我在 viewDidDisappear 上使用这段代码,它通常没问题。

但是,如果我在 viewWillAppearperformSegue

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 应该首先自行管理它。

关于ios - tableview visibleCells 导致崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56704525/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com