iphone - Observer/Dealloc 错误和看不见的 UIViewController 崩溃

标签 iphone ios objective-c uiviewcontroller

我有一个 UIViewController,它有对象在出现时在后台线程上执行一系列任务,并且它被注册为它们的观察者。当他们第一次被调用时,它不再是观察者。

我意识到,如果在显示 View Controller 之前执行这些任务,我可以节省用户时间,所以我对其进行了初始化并调用了一个运行这些任务的方法。

然后我开始出现以下错误:

An instance [insance] of class [class name] was deallocated while key value observers were still registered with it.

如何防止这种情况发生?如果我立即显示 View Controller ,这没问题。

最佳答案

我建议您在这些类的方法 dealloc 中添加调用 [notificationCenter removeObserver: self],您打算将其用作观察者,因为这是彻底注销观察者的最后机会。

关于iphone - Observer/Dealloc 错误和看不见的 UIViewController 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17405694/

相关文章:

iphone - 如何以相同的顺序将字符串的 NSArray 转换为唯一字符串数组?

iphone - 在 iOS 设备上截屏时如何修复丢失的 "blocks"数据?

iphone - Settings.app 中的应用程序首选项

iphone - Interface Builder 背景颜色 => 透明颜色?

iphone - 在横向模式下显示 2 个 PDF 页面

ios - 带有 Collection View POD 的 Swift Carousel

ios - ld : library not found for -lFirebaseCore clang: error: linker command failed with exit code 1 (use -v to see invocation)

objective-c - Objective-C 中的 HTTP Post 请求不起作用

ios - 使用 xcode11 在 ios 13 上运行项目时,基于 View Controller 的旋转停止工作

iphone - YouTube 视频执行后的 iOS View 偏移