使用AsyngImageView崩溃应用程序

时间:2012-01-30 11:09:13

标签: iphone objective-c

我正在使用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'

1 个答案:

答案 0 :(得分:1)

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

我正在将NSString传递给NSURL对象而不进行初始化..