作者:冰淇淋泡火锅_589 | 来源:互联网 | 2023-09-11 17:21
IamhavingacrashinmyCALayersubclasswhenIremovemyselfasanobserverin-(void)dealloc:当我
I am having a crash in my CALayer subclass when I remove myself as an observer in -(void)dealloc:
当我在 - (void)dealloc中以观察者身份移除自己时,我的CALayer子类崩溃了:
- (void)dealloc {
[[NSUserDefaults standardUserDefaults] removeObserver:self forKeyPath:@"showColorLabels"];
[colorLabel release];
[_color release];
[super dealloc];
}
An exception is thrown. It says that self has not been added as an observer. This only happens in a certain case, after [CATransaction flush] is called.
抛出异常。它说自我没有被添加为观察者。这只发生在某种情况下,在调用[CATransaction flush]之后。
I used Instruments to see when the object was allocated. It says it was allocated with the call CALayerGetPresentationLayer(). I am not sure how this works, but I guess this is a copy of my original layer, so init was never called, and I was never added as an observer.
我使用Instruments来查看对象的分配时间。它说它是通过调用CALayerGetPresentationLayer()分配的。我不确定这是如何工作的,但我想这是我原始图层的副本,因此从未调用过init,我从未被添加为观察者。
How can I either check that I am an observer before removing myself, or maybe tell if I am a presentation layer?
如何在删除自己之前检查我是观察者,还是告诉我是否是表示层?
Bridger Maxwell
Bridger Maxwell
2 个解决方案