Permalink
Browse files

Latest places now moved outside of IBAction and triggered when places…

…TableViewController.places is nil.
  • Loading branch information...
1 parent cb37630 commit 4cc3d49503a92e80ef5ee5de089a866b9d12d2f6 @mangoldm committed May 10, 2012
@@ -60,7 +60,7 @@ - (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
[segue.destinationViewController viewController:self chosePhoto:self.chosenAnnotation.photo];
} else {
- // Show photos for a place
+ // Show photos for a place on iPhone
if ([segue.identifier isEqualToString: @"Show Photos for Place Annotation"]) {
id place = self.chosenAnnotation.photo;
@@ -85,7 +85,7 @@ - (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
dispatch_release(photosQueue);
} else {
- // Loop back and update PhotosTableViewController for a place
+ // Loop back and update PhotosTableViewController for a place on iPad
if ([segue.identifier isEqualToString:@"Show Photos for Place Annotation on iPad"]) {
self.chosePlaceAnnotation = YES;
}
@@ -6,14 +6,15 @@
// Copyright (c) 2012 Michael Mangold. All rights reserved.
// CS193P (Fall, 2011) Assignment #5
//
-// This class displays Flickr's top places, then passes
-// the 50 most recent photos to the destination view controller.
+// Displays Flickr's top places, then passes the 50
+// most recent photos to the destination view controller.
//
#import <UIKit/UIKit.h>
#import "MapViewController.h"
@interface PlacesTableViewController : UITableViewController <UINavigationBarDelegate>
+@property (nonatomic, strong) IBOutlet UIActivityIndicatorView *spinner;
@property (nonatomic, strong) NSArray *places;
@property (nonatomic, strong) id chosenPlace;
@end
@@ -15,7 +15,8 @@ @interface PlacesTableViewController () <MapViewControllerDelegate>
@end
@implementation PlacesTableViewController
-@synthesize places = _places;
+@synthesize spinner = _spinner;
+@synthesize places = _places;
@synthesize chosenPlace = _chosenPlace;
- (void)updateSplitViewDetail
@@ -36,13 +37,10 @@ - (void)setPlaces:(NSArray *)places
}
}
-// Refresh button on "Top Places" tab.
-- (IBAction)refresh:(id)sender
+- (NSArray *)RecentPlaces;
{
- // Create spinning 'wait' indicator
- UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
- [spinner startAnimating];
- self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:spinner];
+ NSArray * recentPlaces = [[NSArray alloc] init];
+ [self.spinner startAnimating];
// create GCD queue then dispatch
dispatch_queue_t downloadQueue = dispatch_queue_create("flickr downloader", NULL);
@@ -56,11 +54,18 @@ - (IBAction)refresh:(id)sender
// keep UI processing on main thread
dispatch_async(dispatch_get_main_queue(), ^{
- self.navigationItem.leftBarButtonItem = sender; // Turn off spinning indicator
+ [self.spinner stopAnimating];
self.places = sortedPlacesArray;
});
});
dispatch_release(downloadQueue);
+ return recentPlaces;
+}
+
+// Refresh button on "Top Places" tab.
+- (IBAction)refresh:(id)sender
+{
+ [self RecentPlaces];
}
#pragma mark - Table view data source
@@ -214,13 +219,14 @@ - (void)viewWillAppear:(BOOL)animated
self.navigationController.navigationBar.tintColor = DEFAULT_COLOR;
if (self.places) {
[self updateSplitViewDetail];
+ } else {
+ [self RecentPlaces];
}
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:NO];
-
// Check if segued from place annotation callout accessory
id detail = [self.splitViewController.viewControllers lastObject];
if ([detail isKindOfClass:[MapViewController class]]) {
@@ -98,6 +98,11 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="1" green="0.95436228140000001" blue="0.68379633399999995" alpha="1" colorSpace="calibratedRGB"/>
<color key="separatorColor" red="0.59607845540000004" green="0.2470588386" blue="0.082352943720000002" alpha="1" colorSpace="deviceRGB"/>
+ <activityIndicatorView key="tableFooterView" opaque="NO" contentMode="scaleToFill" hidesWhenStopped="YES" animating="YES" style="whiteLarge" id="1Qp-0M-mN0">
+ <rect key="frame" x="0.0" y="66" width="320" height="37"/>
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
+ <color key="color" red="0.59607845540000004" green="0.2470588386" blue="0.082352943720000002" alpha="1" colorSpace="deviceRGB"/>
+ </activityIndicatorView>
<prototypes>
<tableViewCell contentMode="scaleToFill" selectionStyle="blue" accessoryType="disclosureIndicator" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="Flickr Place" textLabel="y0O-Fv-UPB" detailTextLabel="Na8-Ot-NU6" style="IBUITableViewCellStyleSubtitle" id="dgv-E6-N7N">
<rect key="frame" x="0.0" y="22" width="320" height="44"/>
@@ -140,6 +145,9 @@
</connections>
</barButtonItem>
</navigationItem>
+ <connections>
+ <outlet property="spinner" destination="1Qp-0M-mN0" id="kdv-Ue-Wn8"/>
+ </connections>
</tableViewController>
</objects>
<point key="canvasLocation" x="-30" y="-1292"/>
@@ -347,6 +355,9 @@
</class>
<class className="PlacesTableViewController" superclassName="UITableViewController">
<source key="sourceIdentifier" type="project" relativePath="./Classes/PlacesTableViewController.h"/>
+ <relationships>
+ <relationship kind="outlet" name="spinner" candidateClass="UIActivityIndicatorView"/>
+ </relationships>
</class>
<class className="ScrollingPhotoViewController" superclassName="UIViewController">
<source key="sourceIdentifier" type="project" relativePath="./Classes/ScrollingPhotoViewController.h"/>
@@ -364,7 +375,7 @@
<simulatedScreenMetrics key="destination"/>
</simulatedMetricsContainer>
<inferredMetricsTieBreakers>
- <segue reference="u5J-eu-vGx"/>
<segue reference="xaQ-6t-0TW"/>
+ <segue reference="syE-6f-fM9"/>
</inferredMetricsTieBreakers>
</document>

0 comments on commit 4cc3d49

Please sign in to comment.