【问题标题】:Using AsyngImageView crashes app使用 AsyngImageView 会导致应用崩溃
【发布时间】:2012-01-31 21:02:07
【问题描述】:

我正在使用https://github.com/nicklockwood/AsyncImageView 中的演示示例异步加载图像,但是当我加载应该加载图像的视图时,我的应用程序崩溃了

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

        //common settings
        cell.imageView.frame = CGRectMake(0.0f, 0.0f, 44.0f, 44.0f);
        cell.imageView.contentMode = UIViewContentModeScaleAspectFill;
        cell.imageView.clipsToBounds = YES;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
    }

    //display image path
    cell.textLabel.text = [nnameArray objectAtIndex:indexPath.row];

    //cancel loading previous image for cell
    [[AsyncImageLoader sharedLoader] cancelLoadingURL:cell.imageView.imageURL];

    //set placeholder image or cell won't update when image is loaded
    //cell.imageView.image = [UIImage imageNamed:@"placeholder.png"];

    //load the image
    cell.imageView.imageURL = [pimgArray objectAtIndex:indexPath.row];

    return cell;

    [cell release];
}

pimgArray 是来自 XML 文件的 URL 数组。有人知道为什么这个不起作用吗?

cell.imageView.imageURL = [pimgArray objectAtIndex:indexPath.row];

控制台消息


[Session started at 2012-01-31 13:26:42 +0800.]
2012-01-31 13:26:48.665 EteractApp[6024:207] -[NSCFString isFileURL]: unrecognized selector sent to instance 0x4e103e0
2012-01-31 13:26:48.667 EteractApp[6024:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString isFileURL]: unrecognized selector sent to instance 0x4e103e0'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x00e885a9 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x00fdc313 objc_exception_throw + 44
    2   CoreFoundation                      0x00e8a0bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
    3   CoreFoundation                      0x00df9966 ___forwarding___ + 966
    4   CoreFoundation                      0x00df9522 _CF_forwarding_prep_0 + 50
    5   EteractApp                          0x00016f9d -[AsyncImageCache imageForURL:] + 63
    6   EteractApp                          0x000176f0 -[AsyncImageConnection isInCache] + 75
    7   EteractApp                          0x00018c4c -[AsyncImageLoader updateQueue] + 488
    8   EteractApp                          0x00019407 -[AsyncImageLoader loadImageWithURL:target:success:failure:] + 196
    9   EteractApp                          0x00019450 -[AsyncImageLoader loadImageWithURL:target:action:] + 65
    10  EteractApp                          0x00019be6 -[UIImageView(AsyncImageView) setImageURL:] + 93
    11  EteractApp                          0x0001a2ad -[MyMatches tableView:cellForRowAtIndexPath:] + 878
    12  UIKit                               0x00361b98 -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:] + 634
    13  UIKit                               0x003574cc -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:] + 75
    14  UIKit                               0x0036c8cc -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:] + 1561
    15  UIKit                               0x0036490c -[UITableView layoutSubviews] + 242
    16  QuartzCore                          0x01d9ca5a -[CALayer layoutSublayers] + 181
    17  QuartzCore                          0x01d9eddc CALayerLayoutIfNeeded + 220
    18  QuartzCore                          0x01d440b4 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 310
    19  QuartzCore                          0x01d45294 _ZN2CA11Transaction6commitEv + 292
    20  QuartzCore                          0x01d4546d _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 99
    21  CoreFoundation                      0x00e6989b __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 27
    22  CoreFoundation                      0x00dfe6e7 __CFRunLoopDoObservers + 295
    23  CoreFoundation                      0x00dc71d7 __CFRunLoopRun + 1575
    24  CoreFoundation                      0x00dc6840 CFRunLoopRunSpecific + 208
    25  CoreFoundation                      0x00dc6761 CFRunLoopRunInMode + 97
    26  GraphicsServices                    0x017531c4 GSEventRunModal + 217
    27  GraphicsServices                    0x01753289 GSEventRun + 115
    28  UIKit                               0x002fac93 UIApplicationMain + 1160
    29  EteractApp                          0x00001c58 main + 102
    30  EteractApp                          0x00001be9 start + 53
    31  ???                                 0x00000001 0x0 + 1
)
terminate called after throwing an instance of 'NSException'

【问题讨论】:

  • 能否包含您收到的错误消息? “崩溃”有点模糊......顺便说一句,你应该 autorelease 你的单元格,release 调用 after 方法返回没有任何效果(它从未达到)。
  • 此代码是否来自演示项目.. 它在 xcode 3.2.6 中运行良好
  • 我不太确定如何查看错误消息,他们说运行僵尸但它在我的列表中被禁用,在运行下 - 使用性能工具运行。 stackoverflow.com/questions/5386160/… 我正在使用 xcode 4.3

标签: iphone objective-c


【解决方案1】:
cell.imageView.imageURL = [NSURL URLWithString:[pimgArray objectAtIndex:indexPath.row]];

我没有初始化就将NSString 传递给NSURL 对象..

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多