liuzhiyi1992 / ZYCornerRadius

一句代码,圆角风雨无阻。A Category to make cornerRadius for UIImageView have no Offscreen-Rendered, be more efficiency.

Home Page:http://zyden.vicp.cc/zycornerradius/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

有个dealloc的crash

calvingit opened this issue · comments

present一个vc出来,vc里面初始化为:

- (ZYImageView *)deviceImageView{
    if (!_deviceImageView) {
        _deviceImageView = [ZYImageView zy_roundingRectImageView];
        _deviceImageView.image = [UIImage imageNamed:@"ytb005"];
    }
    return _deviceImageView;
}

图片能够显示出来,在dismiss 的时候crash了,在ZYImageView的dealloc方法挂了

- (void)dealloc {
    if (_hadAddObserver) {
        [self removeObserver:self forKeyPath:@"image"];
    }
}

console输出如下

Trapped uncaught exception 'NSRangeException', reason: 'Cannot remove an observer <ZYImageView 0x12cf74510> for the key path "image" from <ZYImageView 0x12cf74510> because it is not registered as an observer.' 
(
    0   CoreFoundation                      0x00000001833aee50 <redacted> + 148
    1   libobjc.A.dylib                     0x0000000182a13f80 objc_exception_throw + 56
    2   CoreFoundation                      0x00000001833aed80 <redacted> + 0
    3   Foundation                          0x0000000183cc5138 <redacted> + 496
    4   Foundation                          0x0000000183cc4c14 <redacted> + 92
    5   Client                              0x0000000100352628 -[UIImageView(CornerRadius) dealloc] + 96
    6   Client                              0x0000000100353e98 -[ZYImageView dealloc] + 144
    7   Foundation                          0x0000000183d02c80 <redacted> + 92
    8   libobjc.A.dylib                     0x0000000182a2dae8 <redacted> + 508
    9   CoreFoundation                      0x000000018328cabc _CFAutoreleasePoolPop + 28
    10  CoreFoundation                      0x0000000183362c48 <redacted> + 1636
    11  CoreFoundation                      0x000000018328cd10 CFRunLoopRunSpecific + 384
    12  GraphicsServices                    0x0000000184b74088 GSEventRunModal + 180
    13  UIKit                               0x0000000188561f70 UIApplicationMain + 204
    14  Client                              0x0000000100171750 main + 124
    15  libdyld.dylib                       0x0000000182e2a8b8 <redacted> + 4
)
2016-04-11 14:52:52.001 Client[6827:2935922] *** Terminating app due to uncaught exception 'NSRangeException', reason: 'Cannot remove an observer <ZYImageView 0x12cf74510> for the key path "image" from <ZYImageView 0x12cf74510> because it is not registered as an observer.'
*** First throw call stack:
(0x1833aee38 0x182a13f80 0x1833aed80 0x183cc5138 0x183cc4c14 0x100352628 0x100353e98 0x183d02c80 0x182a2dae8 0x18328cabc 0x183362c48 0x18328cd10 0x184b74088 0x188561f70 0x100171750 0x182e2a8b8)

换成UIImageView的接口就可以了

非常感谢,可能是部分修改遗漏了迁移ZYImageView,会尽快修复

------如果选择使用ZYImageView,请删除掉Category UIImageView+CornerRadius------,因为两者API命名一致和Category的**性,使用时调用ZYImageViewAPI同时会调用到Category的API,这个问题是dealloc被调用两次导致。