24
24
25
25
#import " Spot.h"
26
26
27
- #import " AFImageRequestOperation.h"
28
-
29
27
@interface NearbySpotsController ()
30
- @property (strong ) NSArray *nearbySpots;
31
28
@property (strong ) CLLocationManager *locationManager;
32
- @property (strong ) NSOperationQueue *imageOperationQueue;
33
29
34
30
- (void )loadSpotsForLocation : (CLLocation *)location ;
35
31
@end
36
32
37
33
@implementation NearbySpotsController
38
34
@synthesize nearbySpots = _nearbySpots;
39
35
@synthesize locationManager = _locationManager;
40
- @synthesize imageOperationQueue = _imageOperationQueue;
41
- @synthesize tableView = _tableView;
42
36
43
37
- (id )init {
44
38
self = [super init ];
@@ -52,9 +46,6 @@ - (id)init {
52
46
self.locationManager .delegate = self;
53
47
self.locationManager .distanceFilter = 80.0 ;
54
48
55
- self.imageOperationQueue = [[NSOperationQueue alloc ] init ];
56
- self.imageOperationQueue .maxConcurrentOperationCount = 8 ;
57
-
58
49
return self;
59
50
}
60
51
@@ -79,9 +70,7 @@ - (void)loadSpotsForLocation:(CLLocation *)location {
79
70
} else {
80
71
return NSOrderedSame;
81
72
}
82
- }];
83
-
84
- [self .tableView reloadData ];
73
+ }];
85
74
}];
86
75
}
87
76
@@ -91,32 +80,4 @@ - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLoca
91
80
[self loadSpotsForLocation: newLocation];
92
81
}
93
82
94
- #pragma mark - NSTableViewDataSource
95
-
96
- - (NSInteger )numberOfRowsInTableView : (NSTableView *)tableView {
97
- return [self .nearbySpots count ];
98
- }
99
-
100
- // The following is what happens when a longtime iOS dev attempts to work with AppKit. I'm sure there's a _much_ better way to do this.
101
- - (id )tableView : (NSTableView *)tableView objectValueForTableColumn : (NSTableColumn *)tableColumn row : (NSInteger )row {
102
- Spot *spot = [self .nearbySpots objectAtIndex: row];
103
-
104
- if ([[tableColumn dataCell ] isMemberOfClass: [NSImageCell class ]]) {
105
- if (spot.image ) {
106
- return spot.image ;
107
- } else {
108
- NSURLRequest *imageRequest = [NSURLRequest requestWithURL: [NSURL URLWithString: spot.imageURLString]];
109
- AFImageRequestOperation *operation = [AFImageRequestOperation imageRequestOperationWithRequest: imageRequest success: ^(NSImage *image) {
110
- spot.image = image;
111
- [tableView reloadDataForRowIndexes: [NSIndexSet indexSetWithIndex: row] columnIndexes: [NSIndexSet indexSetWithIndex: 0 ]];
112
- }];
113
- [self .imageOperationQueue addOperation: operation];
114
-
115
- return [NSImage imageNamed: @" placeholder-stamp.png" ];
116
- }
117
- } else {
118
- return spot.name ;
119
- }
120
- }
121
-
122
83
@end
0 commit comments