使用iOS-Charts 2.2.3离开Charts VC时,观察者未删除?

时间:2016-03-16 17:46:06

标签: observers ios-charts

我正在努力为我的应用添加一些图表,并且在iOS-Charts 2.1.4中有一个工作版本。更新到iOS-Charts 2.2.3后,从包含我的CombinedChartView的View Controller返回时出现以下错误:

*** Terminating app due to uncaught exception     'NSInternalInconsistencyException', reason: 'An instance 0x168c5a00 of class Charts.CombinedChartView was deallocated while key value observers were still registered with it. Current observation info: <NSKeyValueObservationInfo 0x171366c0> (
<NSKeyValueObservance 0x15d0dda0: Observer: 0x168c5a00, Key path: bounds, Options: <New: YES, Old: NO, Prior: NO> Context: 0x0, Property: 0x15d1b090>
<NSKeyValueObservance 0x15d17a10: Observer: 0x168c5a00, Key path: frame, Options: <New: YES, Old: NO, Prior: NO> Context: 0x0, Property: 0x15db49b0>)'
*** First throw call stack:
(0x217b62eb 0x20f82dff 0x217b6231 0x21f60095 0x20f9d3cd 0x216c9921 0x217774c7 0x216c9bb9 0x216c99ad 0x22943af9 0x259b5fb5 0xf7ed1 0x2137c873)
libc++abi.dylib: terminating with uncaught exception of type NSException

注意:我不会自愿在此VC中注册任何观察员。

有没有人看到最新版本的iOS-Charts?顺便说一下很棒的图库!

知道我可能做错了吗?

2 个答案:

答案 0 :(得分:1)

我不确定您的代码是什么问题,但似乎您的库已损坏。

iOS-charts确实删除了deinit()中的观察者:

port 22: Network is unreachable

但是你的踪迹是

deinit { self.removeObserver(self, forKeyPath: "bounds") self.removeObserver(self, forKeyPath: "frame") }

这是一个悖论。您可能想检查您的图书馆。当组合图表被删除时,应删除观察者。您还可以在Charts.CombinedChartView was deallocated while key value observers were still registered with it中添加中断点以进行调试。

答案 1 :(得分:0)

由于@ Wingzero的建议,我找到了解决方案!

所以我的问题是ChartViewBase.init()方法被调用了两次,因此注册观察者两次,但deinit()只被调用一次,因此有一组重复的观察者被挂起。

双重init()调用的原因是我开始使用v.2.1上的iOS-Charts lib,那时需要在VC的viewDidLoad()中手动初始化CombinedChartView(或者我认为)。随着对iOS-Charts 2.2.3(或Swift 2?)的更新,这不再需要了,并且会导致双重初始化,因此ChartView的一个实例会挂起。

希望这可以帮助其他人遵循相同的2.1 - &gt; 2.2.3 iOS-Charts的更新路径。我必须说,我强烈推荐iOS-Charts作为iOS的图形库。这只是我的错误。

另请注意,cocoaPod还不知道lib的2.2版本。