Note that there are some explanatory texts on larger screens.

plurals
  1. POimages not being added to NSMutableDictionary, which is within an NSOperation
    primarykey
    data
    text
    <p>So I first coded all my methods in a viewcontroller with an NSOperationQueue. After doing some research and a lot of reading I realized i had to subclass my loadImage operation so that I may use isCancelled and cancelAllOperations. So I went ahead and created an nsoperation class and called it from my viewcontroller. ALl the methods are called, even the imageLoaded, but the NSMutableDictionary remains empty. I use the dictionary to populate my tableviewcells using the url as the Key. Also be aware that the operation call in the viewcontroller is within a method which is called by an NSInvocationOperation when the view loads.</p> <pre><code>@interface loadImages : NSOperation { NSURL *targetURL; } @property(retain) NSURL *targetURL; - (id)initWithURL:(NSURL*)url; @end </code></pre> <p>implementation of nsoperation class which includes some other calls to resize the image</p> <pre><code>@implementation loadImages @synthesize targetURL; - (id)initWithURL:(NSURL*)url { if (![super init]) return nil; [self setTargetURL:url]; return self; } - (void)dealloc { [targetURL release], targetURL = nil; [super dealloc]; } - (void)main { NSLog(@"loadImages.m reached"); StoriesTableViewController *stories = [[StoriesTableViewController alloc] init]; NSMutableDictionary *tempDict = stories.filteredImagesDict; UIImage *myImage = [[[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[self targetURL]]]autorelease]; UIImage *scaledImage = [[[UIImage alloc] init] autorelease]; CGRect frame = CGRectMake(100.0f, 100.0f, 180.0f, 180.0f); UIImageView *myImageFrame = [[UIImageView alloc] initWithFrame:frame]; myImage = [[myImage croppedImage:[myImageFrame bounds]]retain]; scaledImage = [[myImage resizedImage:CGSizeMake(120.0f, 120.0f) interpolationQuality:kCGInterpolationHigh]retain]; [tempDict setValue:scaledImage forKey:[self targetURL]]; [stories performSelectorOnMainThread:@selector(imageLoaded:) withObject:myImage waitUntilDone:YES]; NSLog(@"targetURL %@",[self targetURL]); NSLog(@"tempDict count: %d",tempDict.count); [stories release]; [myImage release]; [myImageFrame release]; [scaledImage release]; } </code></pre> <p>creation of nsoperation on viewcontroller</p> <pre><code>for(int i=0;i&lt;storyQuantity;i++) { NSString *imageString = [[[storiesArray objectAtIndex:i] objectForKey: @"image"] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; // must add trimming to remove characters NSURL *url = [NSURL URLWithString:imageString]; loadImages *imageOperation = [[loadImages alloc] initWithURL:url]; [queue_ addOperation:imageOperation]; [imageOperation release]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload