Fixing Mac example to work without AFImageCache coupling

This commit is contained in:
Mattt Thompson 2011-11-21 10:23:50 -06:00
parent 5b5b32c5b8
commit fd2f678ac1
3 changed files with 8 additions and 7 deletions

View file

@ -25,7 +25,6 @@
#import "Spot.h" #import "Spot.h"
#import "AFImageRequestOperation.h" #import "AFImageRequestOperation.h"
#import "AFImageCache.h"
@interface NearbySpotsController () @interface NearbySpotsController ()
@property (strong) NSArray *nearbySpots; @property (strong) NSArray *nearbySpots;
@ -103,19 +102,18 @@
Spot *spot = [self.nearbySpots objectAtIndex:row]; Spot *spot = [self.nearbySpots objectAtIndex:row];
if ([[tableColumn dataCell] isMemberOfClass:[NSImageCell class]]) { if ([[tableColumn dataCell] isMemberOfClass:[NSImageCell class]]) {
NSURL *imageURL = [NSURL URLWithString:spot.imageURLString]; if (spot.image) {
NSImage *image = [[AFImageCache sharedImageCache] cachedImageForURL:imageURL cacheName:nil]; return spot.image;
if (!image) { } else {
NSURLRequest *imageRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:spot.imageURLString]]; NSURLRequest *imageRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:spot.imageURLString]];
AFImageRequestOperation *operation = [AFImageRequestOperation imageRequestOperationWithRequest:imageRequest success:^(NSImage *image) { AFImageRequestOperation *operation = [AFImageRequestOperation imageRequestOperationWithRequest:imageRequest success:^(NSImage *image) {
spot.image = image;
[tableView reloadDataForRowIndexes:[NSIndexSet indexSetWithIndex:row] columnIndexes:[NSIndexSet indexSetWithIndex:0]]; [tableView reloadDataForRowIndexes:[NSIndexSet indexSetWithIndex:row] columnIndexes:[NSIndexSet indexSetWithIndex:0]];
}]; }];
[self.imageOperationQueue addOperation:operation]; [self.imageOperationQueue addOperation:operation];
image = [NSImage imageNamed:@"placeholder-stamp.png"]; return [NSImage imageNamed:@"placeholder-stamp.png"];
} }
return image;
} else { } else {
return spot.name; return spot.name;
} }

View file

@ -27,12 +27,14 @@
@private @private
NSString *_name; NSString *_name;
NSString *_imageURLString; NSString *_imageURLString;
NSImage *_image;
NSNumber *_latitude; NSNumber *_latitude;
NSNumber *_longitude; NSNumber *_longitude;
} }
@property (strong) NSString *name; @property (strong) NSString *name;
@property (strong) NSString *imageURLString; @property (strong) NSString *imageURLString;
@property (strong) NSImage *image;
@property (strong) NSNumber *latitude; @property (strong) NSNumber *latitude;
@property (strong) NSNumber *longitude; @property (strong) NSNumber *longitude;
@property (readonly) CLLocation *location; @property (readonly) CLLocation *location;

View file

@ -27,6 +27,7 @@
@implementation Spot @implementation Spot
@synthesize name = _name; @synthesize name = _name;
@synthesize imageURLString = _imageURLString; @synthesize imageURLString = _imageURLString;
@synthesize image = _image;
@synthesize latitude = _latitude; @synthesize latitude = _latitude;
@synthesize longitude = _longitude; @synthesize longitude = _longitude;
@dynamic location; @dynamic location;