Note that there are some explanatory texts on larger screens.

plurals
  1. POImages wont load from iOS cache
    primarykey
    data
    text
    <p>So, I am attempting to save recently accessed images in the cache and load them back out if they are re-requested. The problem was the images requested from the cache did not show up but the images requested from the web did. However, after lots of fiddling I found that enclosing the cache data function up with a request on the main queue seemed to fix the issue. Can anyone explain to me why it works? I thought I would be on the main queue by default?</p> <pre><code>if([self.fileManager fileExistsAtPath:fileName]){ NSData *theData = [NSData dataWithContentsOfFile:fileName]; dispatch_async(dispatch_get_main_queue(), ^{ // Why does it work now? [self setUpScrollViewWithImageData:theData]; }); }else{ dispatch_queue_t downloadQueue = dispatch_queue_create("flickr download", NULL); dispatch_async(downloadQueue, ^{ NSData *imageData = [NSData dataWithContentsOfURL:image]; dispatch_async(dispatch_get_main_queue(), ^{ [self setUpScrollViewWithImageData:imageData]; [self.fileManager createFileAtPath:fileName contents:imageData attributes:nil]; [self checkCacheSize]; }); }); dispatch_release(downloadQueue); } </code></pre> <p>This is the scrollview setup method</p> <pre><code>-(void)setUpScrollViewWithImageData:(NSData *)imageDataToSetup{ UIImageView *myImage = [[UIImageView alloc] initWithImage:[UIImage imageWithData:imageDataToSetup]]; self.thisImage = myImage; self.myScrollView.delegate =self; self.myScrollView.contentSize = self.thisImage.bounds.size; self.navigationItem.rightBarButtonItem = nil; [self.myScrollView addSubview:self.thisImage]; self.myScrollView.minimumZoomScale = 0.2; self.myScrollView.maximumZoomScale = 5; float w = self.view.bounds.size.width/self.thisImage.bounds.size.width; float h = self.view.bounds.size.height/self.thisImage.bounds.size.height; float zoomRatioMax = MAX(w , h ); float zoomRatioMin = MIN(w , h ); if(zoomRatioMax&lt;1){ [self.myScrollView setZoomScale:zoomRatioMax]; } if(zoomRatioMin&gt;1){ [self.myScrollView setZoomScale:zoomRatioMin]; } } </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.
    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