Permalink
Browse files

read photos asynchronously

  • Loading branch information...
1 parent 9a39967 commit fc4f333ae5066b34e8e1ce07a3286e38d4245afa @nst committed Dec 26, 2009
View
@@ -21,6 +21,8 @@
@property (nonatomic, retain) NSArray *annotations;
+- (void)addAnnotation:(id <MKAnnotation>)annotation;
+
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation;
@end
View
@@ -14,6 +14,10 @@ @implementation SPMapVC
@synthesize annotations;
+- (void)addAnnotation:(id <MKAnnotation>)annotation {
+ [mapView addAnnotation:annotation];
+}
+
- (MKAnnotationView *)mapView:(MKMapView *)aMapView viewForAnnotation:(id <MKAnnotation>)annotation {
if([annotation isKindOfClass:[MKUserLocation class]]) return nil;
@@ -52,7 +56,7 @@ - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view cal
- (void)viewDidLoad {
[super viewDidLoad];
- mapView.showsUserLocation = YES;
+ //mapView.showsUserLocation = YES;
if([annotations count] == 0) return;
@@ -54,23 +54,18 @@ - (NSArray *)jpgPaths {
return a;
}
-- (void)loadData {
- if(contentsDictionaries) return;
+- (void)readPhotosInNewThread {
- UIBarButtonItem *mapButton = [[UIBarButtonItem alloc] initWithTitle:@"Map" style:UIBarButtonItemStylePlain target:self action:@selector(mapButtonClicked:)];
- super.navigationItem.rightBarButtonItem = mapButton;
-
- self.contentsDictionaries = [NSMutableArray array];
- self.annotations = [NSMutableArray array];
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-
NSEnumerator *e = [[self jpgPaths] reverseObjectEnumerator];
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+ NSAutoreleasePool *subpool = [[NSAutoreleasePool alloc] init];
NSString *s = nil;
while(s = [e nextObject]) {
- [pool release];
- pool = [[NSAutoreleasePool alloc] init];
+ [subpool release];
+ subpool = [[NSAutoreleasePool alloc] init];
CLLocationCoordinate2D coord = [UIImage coordinatesOfImageAtPath:s];
if(coord.latitude == 0.0 && coord.longitude == 0.0) continue;
@@ -92,13 +87,30 @@ - (void)loadData {
NSString *dateString = date ? [date description] : @"";
SPImageAnnotation *annotation = [SPImageAnnotation annotationWithCoordinate:coord date:date path:s];
- [annotations addObject:annotation];
+ [annotations performSelectorOnMainThread:@selector(addObject:) withObject:annotation waitUntilDone:YES];
+
+ NSDictionary *cd = [NSDictionary dictionaryWithObject:[NSArray arrayWithObject:coordString] forKey:dateString];
+ [contentsDictionaries performSelectorOnMainThread:@selector(addObject:) withObject:cd waitUntilDone:YES];
- [contentsDictionaries addObject:[NSDictionary dictionaryWithObject:[NSArray arrayWithObject:coordString] forKey:dateString]];
+ [self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:YES];
+
+ [mapVC performSelectorOnMainThread:@selector(addAnnotation:) withObject:annotation waitUntilDone:YES];
}
+ [subpool release];
[pool release];
+}
+
+- (void)loadData {
+ if(contentsDictionaries) return;
+
+ UIBarButtonItem *mapButton = [[UIBarButtonItem alloc] initWithTitle:@"Map" style:UIBarButtonItemStylePlain target:self action:@selector(mapButtonClicked:)];
+ super.navigationItem.rightBarButtonItem = mapButton;
+ self.contentsDictionaries = [NSMutableArray array];
+ self.annotations = [NSMutableArray array];
+
+ [NSThread detachNewThreadSelector:@selector(readPhotosInNewThread) toTarget:self withObject:nil];
}
- (void)dealloc {
Oops, something went wrong.

0 comments on commit fc4f333

Please sign in to comment.