通过URL iOS加载图像时应用程序崩溃

时间:2014-09-23 08:43:48

标签: ios

我的应用程序在下面出现以下代码时崩溃:

[cell.imgViewItem setImageWithURL:imageURL placeholderImage:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
            NSLog(@"Finished");
        } usingActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];

以下是日志跟踪:

2014-09-23 14:11:05.353 SmartSwipe[2834:60b] -[UIImageView sd_cancelImageLoadOperationWithKey:]: unrecognized selector sent to instance 0x79c56ce0
2014-09-23 14:11:05.502 SmartSwipe[2834:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImageView sd_cancelImageLoadOperationWithKey:]: unrecognized selector sent to instance 0x79c56ce0'
*** First throw call stack:
(
    0   CoreFoundation                      0x034031e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x031808e5 objc_exception_throw + 44
    2   CoreFoundation                      0x034a0243 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
    3   CoreFoundation                      0x033f350b ___forwarding___ + 1019
    4   CoreFoundation                      0x033f30ee _CF_forwarding_prep_0 + 14
    5   SmartSwipe                          0x0011c1a8 -[UIImageView(WebCache) sd_cancelCurrentImageLoad] + 56
    6   SmartSwipe                          0x00119744 -[UIImageView(WebCache) sd_setImageWithURL:placeholderImage:options:progress:completed:] + 276
    7   SmartSwipe                          0x0009cc18 -[UIImageView(UIActivityIndicatorForSDWebImage) setImageWithURL:placeholderImage:options:progress:completed:usingActivityIndicatorStyle:] + 504
    8   SmartSwipe                          0x0009c875 -[UIImageView(UIActivityIndicatorForSDWebImage) setImageWithURL:placeholderImage:completed:usingActivityIndicatorStyle:] + 229
    9   SmartSwipe                          0x0003f994 -[QuickScanViewController collectionView:cellForItemAtIndexPath:] + 948
    10  UIKit                               0x02395b30 -[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:] + 257
    11  UIKit                               0x02397775 -[UICollectionView _updateVisibleCellsNow:] + 4730
    12  UIKit                               0x0239b65f -[UICollectionView layoutSubviews] + 265
    13  UIKit                               0x01dbe964 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
    14  libobjc.A.dylib                     0x0319282b -[NSObject performSelector:withObject:] + 70
    15  QuartzCore                          0x007a745a -[CALayer layoutSublayers] + 148
    16  QuartzCore                          0x0079b244 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
    17  QuartzCore                          0x0079b0b0 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
    18  QuartzCore                          0x007017fa _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
    19  QuartzCore                          0x00702b85 _ZN2CA11Transaction6commitEv + 393
    20  QuartzCore                          0x00703258 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
    21  CoreFoundation                      0x033cb36e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
    22  CoreFoundation                      0x033cb2bf __CFRunLoopDoObservers + 399
    23  CoreFoundation                      0x033a9254 __CFRunLoopRun + 1076
    24  CoreFoundation                      0x033a89d3 CFRunLoopRunSpecific + 467
    25  CoreFoundation                      0x033a87eb CFRunLoopRunInMode + 123
    26  GraphicsServices                    0x03f345ee GSEventRunModal + 192
    27  GraphicsServices                    0x03f3442b GSEventRun + 104
    28  UIKit                               0x01d4ff9b UIApplicationMain + 1225
    29  SmartSwipe                          0x001105bd main + 141
    30  libdyld.dylib                       0x04ec5701 start + 1
    31  ???                                 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

请帮助我,我正在努力。提前谢谢。

2 个答案:

答案 0 :(得分:0)

您编写了一个被调用的方法sd_setImageWithURL,该方法为不支持该调用的UIImageView *调用sd_cancelCurrentImageLoad。检查实现sd_cancelCurrentImageLoad的源代码及其功能。

答案 1 :(得分:-1)

请在您的项目中添加SDWebImage框架。 你可以使用cocoapods,在pod文件中使用'pod“SDWebImage”。