0

I'm using the demo example in https://github.com/nicklockwood/AsyncImageView to load images asynchronously, however my app crashes when I load the view that is supposed to load the images

- (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 is an array of URLs from a XML file. Anyone have an idea why this one is not working?

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

Console message


[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'
martti d
  • 2,552
  • 2
  • 17
  • 20
  • 2
    Could you include the error messages you're getting? "Crash" is a bit vague... Btw, you should `autorelease` your cell, the `release` call _after_ the method returns has no effect whatsoever (it's never reached). – omz Jan 30 '12 at 11:19
  • is this code is from the demo project.. it running fine in xcode 3.2.6 – vishy Jan 30 '12 at 11:22
  • im not really sure how to see the error messages, they say run zombie but its disabled in my list, Under Run - Run with performance tool. http://stackoverflow.com/questions/5386160/how-to-enable-nszombie-in-xcode im using xcode 4.3 – martti d Jan 31 '12 at 02:37

1 Answers1

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

I was passing a NSString to the NSURL object without initializing it..

Matt Wilko
  • 26,994
  • 10
  • 93
  • 143
martti d
  • 2,552
  • 2
  • 17
  • 20