我有一个 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/