最近接手一个 国际化的项目,做下笔记(笔记若有误,欢迎指出),记录一下开发遇到报错问题:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'An instance 0x129d0c230 of class HDTabBarController was deallocated while key value observers were still registered with it. Current observation info: <NSKeyValueObservationInfo 0x17003d7a0> (
<NSKeyValueObservance 0x170246360: Observer: 0x129d0c230, Key path: selectedViewController, Options: <New: YES, Old: YES, Prior: NO> Context: 0x0, Property: 0x170246390>
开发环境Xcode12.1,运行环境iOS10.3.3、iOS14.2。
iOS14.2手机运行没问题
iOS10.3.3手机上运行,切换语言时(重置HDTabBarController)APP崩溃闪退。报错如下
检查发现 HDTabBarController 在dealloc 时没有移除KVO监听(如图)。
解决方案:
在重置HDTabBarController时,原来的HDTabBarController需要释放,对应的KVO也需要移除。所以在dealloc里面添加移除KVO监听就好了, 如下图