2

I have a problem with a piece of code that should add images to a NSMutableArray. For some reason the images are not added (the count of the array stays at 0). Can someone please tell me what I'm doing wrong here?

- (void)incomingNotification:(NSNotification *)notification {
    [self.popoverController dismissPopoverAnimated:YES];
    _URLString = [notification object];

    for (int i = 0; i < [[self returnLargeUrls] count]; i++) {
        [self getImageFromURL:_URLString];
    }
}

And in getImageFromUrl::

-(NSData *) getImageFromURL:(NSString *)fileURL {
    UIImage *result;
    NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:fileURL]];
    result = [UIImage imageWithData:data];

    [self.pageImages addObject:result];

    NSLog(@"%d", self.pageImages.count);
    return data;
}
2
  • wt is [self returnLargeUrls] ?? Commented Mar 25, 2013 at 14:10
  • 1
    NSLog your the result of getImageFromURL make sure it isn't null, then NSLog the results of returnLargeURLs and make sure it isn't empty. Commented Mar 25, 2013 at 14:12

2 Answers 2

1

The first thing to check would be that you property pageImages is not nil to begin with.

You can check that like:

if(!pageImages)
    NSLog(@"The NSMutableArray pageImages is NIL. Damn... :(");

This is most likely your problem.

Sign up to request clarification or add additional context in comments.

Comments

0
  1. Make sure you alloc init your NSMutableArray first.
  2. Make sure your NSData is not nil after fetching contents from URL. NSLog(@"%@", data);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.